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
298
votes
13 answers

How do I get the file name from a String containing the Absolute file path?

String variable contains a file name, C:\Hello\AnotherFolder\The File Name.PDF. How do I only get the file name The File Name.PDF as a String? I planned to split the string, but that is not the optimal solution.
Sharon Watinsan
  • 9,620
  • 31
  • 96
  • 140
284
votes
15 answers

Maximum filename length in NTFS (Windows XP and Windows Vista)?

I'm designing a database table which will hold filenames of uploaded files. What is the maximum length of a filename in NTFS as used by Windows XP or Vista?
GateKiller
  • 74,180
  • 73
  • 171
  • 204
276
votes
6 answers

How can I create a full path to a file from parts (e.g. path to the folder, name and extension)?

I need to pass a file path name to a module. How do I build the file path from a directory name, base filename, and a file format string? The directory may or may not exist at the time of call. For…
Damon Julian
  • 3,829
  • 4
  • 29
  • 34
274
votes
14 answers

How do I get a file name from a full path with PHP?

For example, how do I get Output.map from F:\Program Files\SSH Communications Security\SSH Secure Shell\Output.map with PHP?
omg
  • 136,412
  • 142
  • 288
  • 348
269
votes
6 answers

Change case of a file on Windows?

There are a couple of files in our git-controlled codebase that I'd like to rename. Specifically, I just want to change the case of the file, so that sourceCode.java becomes SourceCode.java, for example. The catch: I'm on a Windows box, and the…
Electrons_Ahoy
  • 36,743
  • 36
  • 104
  • 127
253
votes
8 answers

How can I replace (or strip) an extension from a filename in Python?

Is there a built-in function in Python that would replace (or remove, whatever) the extension of a filename (if it has one)? Example: print replace_extension('/home/user/somefile.txt', '.jpg') In my example: /home/user/somefile.txt would become…
ereOn
  • 53,676
  • 39
  • 161
  • 238
244
votes
7 answers

Git copy file preserving history

I have a somewhat confusing question in Git. Lets say, I have a file dir1/A.txt committed and git preserves a history of commits Now I need to copy the file into dir2/A.txt (not move, but copy). I know that there is a git mv command but I need…
Mark Bramnik
  • 39,963
  • 4
  • 57
  • 97
239
votes
10 answers

Get file name from URI string in C#

I have this method for grabbing the file name from a string URI. What can I do to make it more robust? private string GetFileName(string hrefLink) { string[] parts = hrefLink.Split('/'); string fileName = ""; if (parts.Length > 0) …
paulwhit
  • 8,719
  • 4
  • 29
  • 30
224
votes
8 answers

Allowed characters in filename

Where can I find a list of allowed characters in filenames, depending on the operating system? (e.g., on Linux, the character : is allowed in filenames, but not on Windows)
python dude
  • 7,980
  • 11
  • 40
  • 53
176
votes
29 answers

Get file name from URL

In Java, given a java.net.URL or a String in the form of http://www.example.com/some/path/to/a/file.xml , what is the easiest way to get the file name, minus the extension? So, in this example, I'm looking for something that returns "file". I can…
Sietse
  • 7,884
  • 12
  • 51
  • 65
170
votes
14 answers

Use jQuery to get the file input's selected filename without the path

I used this: $('input[type=file]').val() to get the file name selected, but it returned the full path, as in "C:\fakepath\filename.doc". The "fakepath" part was actually there - not sure if it's supposed to be, but this is my first time working…
marky
  • 4,878
  • 17
  • 59
  • 103
158
votes
8 answers

Is it possible to use "/" in a filename?

I know that this is not something that should ever be done, but is there a way to use the slash character that normally separates directories within a filename in Linux?
subcan
  • 2,021
  • 2
  • 18
  • 21
152
votes
3 answers

How to get folder name, in which given file resides, from pathlib.path?

Is there something similar to os.path.dirname(path), but in pathlib?
trainset
  • 2,079
  • 3
  • 13
  • 17
146
votes
6 answers

A html space is showing as %2520 instead of %20

Passing a filename to the firefox browser causes it to replace spaces with %2520 instead of %20. I have the following HTML in a file called myhtml.html: When I load myhtml.html into…
Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
146
votes
8 answers

DateTime.ToString() format that can be used in a filename or extension?

I want to add a timestamp to filenames as files are created but most of the DateTime methods I've tried output something with spaces and slashes. For instance: Debug.WriteLine(DateTime.Now.ToString()); // <-- 9/19/2012 1:41:46…
pdizz
  • 4,100
  • 4
  • 28
  • 42