Given a filesystem path, is there a shorter way to extract the filename without its extension?

I program in WPF C#. I have e.g. the following path: C:\Program Files\hello.txt and I want to extract hello from it. The path is a string retrieved from a database. Currently I’m using the following code to split the path by ‘\’ and then split again by ‘.’: string path = “C:\\Program Files\\hello.txt”; string[] pathArr … Read more

How to replace spaces in file names using a bash script

Can anyone recommend a safe solution to recursively replace spaces with underscores in file and directory names starting from a given root directory? For example: $ tree . |– a dir | `– file with spaces.txt `– b dir |– another file with spaces.txt `– yet another file with spaces.pdf becomes: $ tree . |– … Read more

Extract file basename without path and extension in bash [duplicate]

This question already has answers here: Extract filename and extension in Bash (38 answers) Closed 5 years ago. Given file names like these: /the/path/foo.txt bar.txt I hope to get: foo bar Why this doesn’t work? #!/bin/bash fullfile=$1 fname=$(basename $fullfile) fbname=${fname%.*} echo $fbname What’s the right way to do it? 9 Answers 9

How do I manually create a file with a . (dot) prefix in Windows? For example, .htaccess

I want to create a .htaccess file manually and discovered it seems impossible through the Windows UI. I get a “you must type a filename.” message. There has to be a way to create files with . as a prefix in Windows. Can this be done manually? 16 Answers 16 Windows 7, 8 & 10 … Read more

How do I remove the file suffix and path portion from a path string in Bash?

Given a string file path such as /foo/fizzbuzz.bar, how would I use bash to extract just the fizzbuzz portion of said string? 14 Answers 14 Here’s how to do it with the # and % operators in Bash. $ x=”/foo/fizzbuzz.bar” $ y=${x%.bar} $ echo ${y##*/} fizzbuzz ${x%.bar} could also be ${x%.*} to remove everything after … Read more

C++ code file extension? What is the difference between .cc and .cpp [closed]

Closed. This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 2 years ago. The community reviewed whether to reopen this question 5 months ago and left it closed: Original close reason(s) were … Read more