File naming
How we name files can enhance their utility.
Of course, many programs define their own filenames and those cannot be changed, but outputs from those programs that are not going to be used or changed directly by them can be renamed.
There is always something useful they can store.
Where
△Where files are stored or used will place limits on what characters are allowed.
- a.Some operating systems ignore case, like Windows, but others do not, like Linux. That means that it will be better to use lowercase letters in names to allow the file to be used anywhere without possible sorting or identification issues.
- b.Many filesystems do not handle Unicode characters consistently and that can vary between operating systems.
- c.Each operating system uses special characters in their command line utilities, and those cannot be used in filenames.
- d.All filesystems use a
.before the extension. If processing the filenames programmatically, use it as the major separator between filename parts to split it only once to isolate those parts. - e.At some point, a filename may need to be displayed on a web page. While many people may use a
_to separate words in filenames, on a web page the name will not automatically wrap at them, possibly leading to extra long names that push past the page boundary. Use-instead which do wrap. - f.Some operating systems impose limits on filename lengths or total path length. For example, Windows restricts paths to 256 characters.
While Windows 10 or 11 can be made to allow longer path lengths, a registry setting is required which is probably only been done on very few systems. While Linux allows up to 4096 character path lengths, MacOS, though also based upon Unix, only allows 1024. Use a maximum of 1024 on webservers to be safe and be readable in site management pages.
Information
△A lot of information can be stored in the filename to avoid having to open it.
- a.Format of
yyyy-mm-ddoryyyy-mm-dd-hh-mm-ss, depending upon the granularity required. The separators make them far easier to read. Keep leading0s to facilitate sorting and direct comparisons. - b.finance or fin if the mnemonics are generally understood. If wanting to compare across different filenames while still being able to compare other parts, make them all the same length by using constant-length mnemonics.
- c.
w,dandrfor works-in-progress, drafts and releases respectively.
All internal refences for elements, like articles and files, in my Smallsite Design website design app use their create date, so all filenames use the format yyyy-mm-dd-hh-mm-ss for those in their filenames and folders.
Order
△Many utilities, like file managers, default to sorting filenames alphabetically and that can be used to groups files according to the order of information in the name.
The key to sorting visually and having ease of processing is to make the content in each part the same length across all filenames. Then order the parts in the way you want to see them listed in your file manager, which will save having to open another program to show them in order.
While file extensions are usually used to distinguish which programs files are managed by, they are at the end of names and so are useless for sorting by program if other parts of the filename are sort criteria. Use a short mnemonic at or near the start of filenames if wanting to significantly sort by program.
If programmatically processing files or folders, timestamps (date and time) will typically be first as the file-reading functions like
Benefits
△Having reliably formatted filenames means that other applications may benefit.
Filenames with known formats become usable by other applications or new ones can be written to take advantage of the names. For example, documents for a product can start with the company mnemonic, product id, release number, project id, phase and extension. A utility can then be written to collect all release phase documents for all products, copy them to a webserver, and make a page with a section for each product with a list of releases, latest first, for the standard product then each project's versions.
Another utility can scour the document repositories and send an email to their documentation managers with a list of all filenames with format errors. Both these utilities can save hundreds of hours of manual maintenance merely because the formal filename formats allow reliable processing.
Filenames are also an easy way to store modest amounts of information without giving them any content. They only require being read from a folder listing. This makes them good for recording asynchronous information rather than using a database with all its overhead. A later process can aggregate them for storage in a single file.
For example, after 30 seconds of a web page being open, a mini-page inline in an iframe element can send the page id, a timestamp and any other desired information like its locale to the website, where it is turned into a file with the received information solely in its filename. A regular aggregation process can then read all the new read files, add their information to a read statistics file and then delete them.
The examples cited have all been done for real, with the later being used in Smallsite Design to show read statistics for each article of a site, which is the most important site statistic, and without using JavaScript.