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
143
votes
5 answers

How to apply a Git patch to a file with a different name and path?

I have two repositories. In one, I make changes to file ./hello.test. I commit the changes and create a patch from that commit with git format-patch -1 HEAD. Now, I have a second repository that contains a file that has the same contents as…
mart1n
  • 5,969
  • 5
  • 46
  • 83
141
votes
23 answers

Sanitizing strings to make them URL and filename safe?

I am trying to come up with a function that does a good job of sanitizing certain strings so that they are safe to use in the URL (like a post slug) and also safe to use as file names. For example, when someone uploads a file I want to make sure…
Xeoncross
  • 55,620
  • 80
  • 262
  • 364
139
votes
1 answer

Preferred (or most common) file extension for a Python pickle

At times, I've seen .pickle, .pck, .pcl, and .db for files that contain Python pickles, but I am unsure what is the most common or best practice. I know that the latter three extensions are also used for other things. The related question is: What…
Raymond Hettinger
  • 216,523
  • 63
  • 388
  • 485
136
votes
11 answers

How to rename with prefix/suffix?

How do I do mv original.filename new.original.filename without retyping the original filename? I would imagine being able to do something like mv -p=new. original.filename or perhaps mv original.filename new.~ or whatever - but I can't see anything…
Peter Boughton
  • 110,170
  • 32
  • 120
  • 176
135
votes
11 answers

Log4net rolling daily filename with date in the file name

I would like to have files named for example: dd.mm.yyyy.log How is this possible with log4net?
JL.
  • 78,954
  • 126
  • 311
  • 459
130
votes
11 answers

How to get file name from content-disposition

I downloaded a file as response of ajax. How to get the file name and file type from content-disposition and display thumbnail for it. I got many search results but couldn't find right way. $(".download_btn").click(function () { var uiid =…
Arun Sivan
  • 1,680
  • 2
  • 12
  • 23
127
votes
6 answers

What is your favorite date and time format in a file name?

This is a somewhat subjective question, and not very important in the big scheme of things, but something that yet annoys me regularly. There seems to be no self-evident way to put a timestamp in a file name. Objective issue is that timestamps in…
mika
  • 6,812
  • 4
  • 35
  • 38
125
votes
11 answers

Linux - Replacing spaces in the file names

I have a number of files in a folder, and I want to replace every space character in all file names with underscores. How can I achieve this?
Mithun Sreedharan
  • 49,883
  • 70
  • 181
  • 236
122
votes
6 answers

Should Python class filenames also be camelCased?

I know that classes in Python are typically cased using camelCase. Is it also the normal convention to have the file that contains the class also be camelCase'd especially if the file only contains the class? For example, should class className also…
m4jesticsun
  • 1,799
  • 3
  • 12
  • 12
114
votes
6 answers

Renaming part of a filename

I have loads of files which look like this: DET01-ABC-5_50-001.dat ... DET01-ABC-5_50-0025.dat and I want them to look like this: DET01-XYZ-5_50-001.dat ... DET01-XYZ-5_50-0025.dat How can I do this?
not_a_geek
  • 1,157
  • 2
  • 9
  • 6
112
votes
5 answers

Why do I get a SyntaxError for a Unicode escape in my file path?

The folder I want to get to is called python and is on my desktop. I get the following error when I try to get to it >>> os.chdir('C:\Users\expoperialed\Desktop\Python') SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in…
inspired
  • 1,127
  • 2
  • 8
  • 5
111
votes
16 answers

How to make a valid Windows filename from an arbitrary string?

I've got a string like "Foo: Bar" that I want to use as a filename, but on Windows the ":" char isn't allowed in a filename. Is there a method that will turn "Foo: Bar" into something like "Foo- Bar"?
Ken
  • 2,651
  • 3
  • 19
  • 17
102
votes
16 answers

Getting the names of all files in a directory with PHP

For some reason, I keep getting a '1' for the file names with this code: if (is_dir($log_directory)) { if ($handle = opendir($log_directory)) { while($file = readdir($handle) !== FALSE) { $results_array[] =…
Dexter
  • 5,666
  • 6
  • 33
  • 45
102
votes
9 answers

Rename multiple files in a folder, add a prefix (Windows)

I'd like to batch rename files in a folder, prefixing the folder's name into the new names. i.e. files in C:\house chores\ will all be renamed house chores - $old_name.
ofer.sheffer
  • 5,417
  • 7
  • 25
  • 26
102
votes
3 answers

What is the best way to combine a path and a filename in C#/.NET?

What is the best way to combine a path with a filename? That is, given c:\foo and bar.txt, I want c:\foo\bar.txt. Given c:\foo and ..\bar.txt, I want either an error or c:\foo\bar.txt (so I cannot use Path.Combine() directly). Similarly for c:\foo…
Rasmus Faber
  • 48,631
  • 24
  • 141
  • 189