====== Creating Valid Filenames ====== Microsoft Windows, Unix and MacOS have different limits on what characters can be used in file names, what the maximum length of a filename can be, and the maximum length of the full file name (device + path + filename). MacOS is built on Unix (with some fantastic enhancements), so we will use the term Unix to include MacOS. Note that the same rules apply for directory (folder) names. When this document says "file name", it is talking about directory names also. ===== Quick and Easy ==== For maximum flexibility, if sharing files amongst more than one operating system/file system, file names should contain only the following characters * Letters (a-z), see note below * Digits (0-9) * Underscore (_) * Hyphen aka Dash (-) * Dot or period (.), see note below * Space ( ), see note below A good rule of thumb for creating good file names is one that matches all of the following: * Name must start and end with a letter or number * File name must be at least 5 characters long (see below) ==== Letters ==== Unix is case sensitive, meaning a capital 'A' is different from a lower case 'a'. Windows is not, so having a Windows computer using files fromUnix can cause problems. //A.txt// and //a.TXT// are two different files for Unix, but you can get a //Duplicate File Name// error if both exist in the same directory you access from Windows. You should come up with a standard so that duplicate file names (from Windows perspective) do not cause problems. The standard can be as simple as "use only lower case letters" or more complex. ==== Dot or period ==== Under Unix, a leading dot is an indicator of a file or directory which is hidden by default. It usually contains configuration information. Windows does not allow a dot as the last character in a file or directory name, so a file name should never have a dot as the first or last character. ==== Space ==== Spaces are quite useful for separating words in a filename or directory name, but they can cause problems when working from the command line. However, most people who use the command line already have work arounds for it, though they normally use underscores instead. However, a file name must never begin or end with a space. Most GUI platforms (Windows, MacOS, Unix) automatically remove leading and trailing blank spaces, but it is possible to get it to happen accidently anyway. If this happens, you may require the help of a computer technician to gain access to the file. ===== File Name length ===== This is tricky, as there are two parts to it; the maximum length of the file name itself, and the maximum length of the entire path (all directories above the file name). The simplest solution is to never have a file name longer than 255 characters (including the drive letter under Windows, the full list of all directories, the extension plus one for the period and one for each directory) ==== Individual file name length ==== All of the current operating systems will handle a file name up up to 255 characters. This includes the extension and the period separating them. However, if using Microsoft Windows, see the overall length restriction below. ==== Overall Length ==== The overall length is the full path to the file, including the file and directory separators. As an example, on a Windows machine, a file named test, which is a text file on the C drive, in the directory (folder) john, which is under the folder doe, would have an overall length of 20 characters. Most people don't see this, but the actual location of that would be c:\doe\john\test.txt The colon (:) designates the C to be a drive letter, and the backslashes separate the directory list. The .txt tells Windows what type of file it is (and what program to open it with). By default, Microsoft Windows has a limit of 255 characters for everything. This can be overridden by enabling the LongPathsEnabled policy under Windows, extending the overall full file name (path plus file) to 32 thousand characters. For compatiblity with other systems, consider a maximum length of 255 characters. By default, MacOS has a maximum of about a thousand characters for the full path, but many configurations have it extended to over 4000 Other Unicies tend to default to over 4000 (4096, to be precise) characters for the full path name.