Questions tagged [filenames]

Filenames are metadata about a file; a string used to uniquely identify a file stored on the file system of a computer.

The filename is metadata about a file; a special kind of string used to uniquely identify a file stored on the file system of a computer. Some operating systems also identify directories in the same way. Different operating systems impose different restrictions on length and allowed characters on filenames.

4148 questions
2762
votes
38 answers

Extract filename and extension in Bash

I want to get the filename (without extension) and the extension separately. The best solution I found so far is: NAME=`echo "$FILE" | cut -d'.' -f1` EXTENSION=`echo "$FILE" | cut -d'.' -f2` This is wrong because it doesn't work if the file name…
ibz
  • 44,461
  • 24
  • 70
  • 86
1782
votes
33 answers

Extracting extension from filename in Python

Is there a function to extract the extension from a filename?
Alex
  • 43,191
  • 44
  • 96
  • 127
800
votes
6 answers

How to loop over files in directory and change path and add suffix to filename

I need to write a script that starts my program with different arguments. I start my program with: ./MyProgram.exe Data/data1.txt [Logs/data1_Log.txt]. Here is the pseudocode for what I want to do: for each filename in /Data do for int i = 0, i =…
Dobrobobr
  • 8,216
  • 4
  • 17
  • 18
750
votes
17 answers

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

I have seen C++ code saved as both .cc and .cpp files. Is there a difference between the two? The Google style guide seems to suggest .cc, but provides no explanation. I am mainly concerned with programs on Linux systems.
Jessica
  • 1,421
  • 5
  • 15
  • 10
631
votes
20 answers

What characters are forbidden in Windows and Linux directory names?

I know that / is illegal in Linux, and * " / \ < > : | ? are illegal in Windows. What else am I missing? I need a comprehensive guide that also accounts for double-byte characters.
Jeff
  • 14,831
  • 15
  • 49
  • 59
513
votes
15 answers

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?
Redwood
  • 66,744
  • 41
  • 126
  • 187
468
votes
17 answers

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?
Doug Chamberlain
  • 11,192
  • 9
  • 51
  • 91
454
votes
3 answers

Getting the filenames of all files in a folder

I need to create a list with all names of the files in a folder. For example, if I have: 000.jpg 012.jpg 013.jpg I want to store them in a ArrayList with [000,012,013] as values. What's the best way to do it in Java ? PS: I'm on Mac OS X
user680406
  • 5,637
  • 6
  • 24
  • 19
444
votes
9 answers

Extract file basename without path and extension in bash

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?
neversaint
  • 60,904
  • 137
  • 310
  • 477
430
votes
19 answers

Get names of all files from a folder with Ruby

I want to get all file names from a folder using Ruby.
Željko Filipin
  • 56,372
  • 28
  • 94
  • 125
428
votes
27 answers

Turn a string into a valid filename?

I have a string that I want to use as a filename, so I want to remove all characters that wouldn't be allowed in filenames, using Python. I'd rather be strict than otherwise, so let's say I want to retain only letters, digits, and a small set of…
Sophie Gage
  • 5,391
  • 5
  • 24
  • 25
345
votes
22 answers

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…
armandino
  • 17,625
  • 17
  • 69
  • 81
308
votes
6 answers

.c vs .cc vs. .cpp vs .hpp vs .h vs .cxx

Possible Duplicates: *.h or *.hpp for your class definitions Correct C++ code file extension? .cc vs .cpp I used to think that it used to be that: .h files are header files for C and C++, and usually only contain declarations. .c files are C…
user541686
  • 205,094
  • 128
  • 528
  • 886
306
votes
8 answers

What is the naming standard for path components?

I keep getting myself in knots when I am manipulating paths and file names because I don’t follow a naming standard for path components. Consider the following toy problem (Windows example, but hopefully the answer should be platform independent).…
Oddthinking
  • 24,359
  • 19
  • 83
  • 121
305
votes
10 answers

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…
KMC
  • 19,548
  • 58
  • 164
  • 253
1
2 3
99 100