File naming

There are various ways for software to name files automatically.

This lesson describes the file naming strategies in detail, among respective benefits and shortcomings.

Multiple strategies may be applied to the same file names, as described in.

Time stamps
File names are automatically generated from the current date and time, usually with descending order until second (→ISO 8601).


 * Examples:
 * (no separators)
 * (underscore separator)
 * (dash separator)
 * (note: colons in file names are unsupported by many file systems, →)

File names may include prefixes such as  and.

If more than one file is created within one second, such as in burst photography, a suffix number may be added before the file extension, such as  or , or milleseconds, such as   or.

Mobile phone camera software commonly uses this method.

This method safely prevents duplicate file names which may cause confusion and clobbering (overwriting) if handled improperly, such as when using the  command without the   flag. Naming conflicts when merging files from multiple devices into one place are also avoided.
 * Benefits

In addition, during file transfers between systems, the file attributes containing the date and time information may be dismissed and reset. If the file's internal meta data does not contain date and time information, the file name is the only location where the otherwise lost date and time information is stored. To avoid losing such information, a list of files with dates and times should recommendedly be created before initiating a file transfer.

Searches for files by time are facilitated, because all file searching software is able to search for files by name, while not all software is able to search by file time attributes or internal metadata time stamp usually found in photo and video files.

Time-based selection of files is facilitated using wildcards, as usually supported by command prompt and terminal software, for time-based file operations such as copying all photos and videos from a specific day or month. As an example, the asterisk wildcard  would match all videos captured in July of 2024, if the camera software uses a   file name format.

There is no realistic limit of possible file names at a fixed name length, while on numbered files with a too short fixed length (e.g. four digits) not split between directories, the possible number of file names might foreseeably be exhausted, where a variable digit length (e.g.  followed by  ) might be presented in an incorrect order in alphanumerical file sorting, if number detection is not implemented into the file management software.

Pasting
Time stamps can be set to be pasted with a keyboard shortcut, implemented through AutoHotKey for Windows and xdotool for Linux.

For example, this AutoHotKey script pastes the time stamp when pressing Alt + 2. Alt & 2:: Send, %A_Now% Return does the same as, which is pasting a   time stamp, such as.
 * AutoHotKey (Windows)

On Linux, a keyboard shortcut can be assigned to call this example script, which can be modified to suit one's needs. It requires  to be installed.
 * xdotool (Linux)

(synonymous with ) adds a fifth-second delay before pasting the time stamp to prevent pasting prior to the key being released, possibly causing a part of the output to be omitted.

Numbering
This method is commonly used among digital cameras and camcorders due to lack of internet connectivity or GPS reception which would be necessary for the clock to set automatically, and some users not bothering with setting the date and time before starting to operate the device.

When storing on a new (or cleared) memory card, some digital cameras and other software starts over counting (based on the last used file number), while others keep a memory of the last used number, stored in a local variable, the latter of which prevents duplicate file names when moving to a common place.


 * Examples

Digital cameras may split the files between directories per day or per 999 or 1000 files:



This naming scheme is used by at least several Panasonic Lumix digital cameras.

Numbered file names facilitate counting files and noticing files that possibly went missing during a transfer.
 * Benefits

If the device's clock setting is incorrect as described above, the file names will not carry wrong date and time information. Some devices such as standalone flat bed (paper) scanners which allow direct saving to flash drives and/or memory cards may lack a clock setting entirely, which may make the date and time information appear as 1970-01-01, the Unix epoch.

Numbered file names are usually shorter than timestamped ones. With modern file systems however which are not limited to eight-point-three file names, this benefit is only marginial.

Combination
A combination of both naming strategies may be used, combining the benefits. In practice, this has not been commonly implemented so far.


 * Examples
 * (The leading zeroes for file numbers are not necessary here for correct sorting, due to the time stamp preceeding it, but they may be necessary for a constant file name length, to prevent irritatingly protruding file names in a list.)
 * (With leading zeroes.)
 * (The leading zeroes for file numbers are not necessary here for correct sorting, due to the time stamp preceeding it, but they may be necessary for a constant file name length, to prevent irritatingly protruding file names in a list.)
 * (With leading zeroes.)
 * (With leading zeroes.)

Contextual
Contextual file names, often used in addition to a time stamp, may contain information such as location or opened software.

The contextual information may be applied prior to or after the file name:


 * – Location name option in the camera software of some Samsung mobile phones since 2013.
 * – Application title name, before time stamp, as used by Samsung Mobile since Android 8.0 Oreo.
 * – Application package name, after time stamp, as used by Xiaomi Mobile.

Manual
Consider adding short notes to names of multimedia files such as screen shots, photos, videos, voice notes, etc., as they are not searchable like text.

Screenshots' text may be searchable using character recognition software, but scanning each picture for text would be far slower (presumably over 100 times) than directly machine-readable text, and as of 2021, no open-source software for this purpose appears to exist.

File names for downloaded media like videos should include a title and may include the source ID and date stamp and author name to facilitate finding. A format example is " ".

Disk images' file names may include the data storage type (e. g. SSD, HDD, BD-R), the vendor name, vendor-specified size, and the approximate date of purchase. If the image is intended for long-term archival rather than a short-term backup, the current date stamp (e. g. " ") should be written as well. An example is ").

Characters like a colon and a question mark, as well as duplicate file and directory names with only letter case differences (e. g. " " and " "), should be avoided from to ensure support across file systems and operating systems.

Since file managers typically allow jumping to files in a directory listing by typing in the file name from the beginning, choose the start of the file name by which information you would like to type in. For example, if you wish to jump to a file in the directory listing by typing in a date, start the file name with that. If you wish to jump to a file by a name or location, put that at the beginning of the file name. As of 2022, file managers are not known to have a search feature that only searches the current directory listing without sub directories, but this can be done in the terminal (command prompt) using wildcard characters.

Characters
Use of the following characters should be avoided wherever possible, due to limited support or automatic substitution among file systems and resource locator types:


 * (space character) — Inconvenient in Unix/Linux terminal auto completion (needs backslash escaping if not within quotation marks); substituted with  in URL and   (underscore) in MediaWiki.
 * (colon) — Possible compatibility issues; reserved for drive letters in Microsoft Windows (e.g. ).
 * (equal sign) — Might be parsed as variable modifier in Bash and MediaWiki.

Mistakes
The following mistakes should be avoided:
 * Clobbering (overwriting) existing files: This is more likely to happen on applications which use static file names (e.g. for data exports), where an existing file always causes a naming collision, but might happen on deficient implementations where numbered files are written from a local number variable without verifying that the file name is not reserved.

Temporary names
Software may give files a temporary name while it is being processed. For example, the Firefox web browser appends " " to the file name, and Chrome " ". The benefits are that it distinguishes the file, and signifies to the user that the file is incomplete if the download was interrupted. However, a disadvantage is that it interferes with streaming a multimedia file in a locally installed media player software during download.

When saving a file, a  file may be created to prevent corruption in case of a failed write. This may be caused by a power outage, operating system crash, or disk space exhaustion.

Additional tips

 * Manual file naming does not have always to be completely consistent where the benefit of sparing efforts needed for maintaining such outweighs, for example for names of text files containing drafted text snippets, where content can be ped through rapidly when necessary.