A brief introduction to best practices for file and directory naming that will help keep you sane.
This is a brief note on best practices for naming files and directories. There is no universal convention that I am aware of but you can save yourself a lot of trouble by following a few simple rules when naming files and directories.
Your task is to ensure your files are Machine readable and Human readable.
Never use special characters in your file name
(e.g., * # : \ / < > | " ? [ ] ; = + & £ $
, and
so on). Letters and numbers only. Many of these symbols
are prohibited and a lot of software will reject files that contain
these symbols.
Periods .
should only be used for a file extension, like
document.html
. If you put a period .
at the
beginning of a file or directory name, like .bash_profile
,
then it will be hidden by default. Do not do this at the beginning of a
name unless you know what you are doing :)
Do not use spaces. Separate words using a dash
(-
) or an underscore (_
), like
how-to-use-this-site.Rmd
. You can also use camel case if
you prefer, like howToUseThisSite.Rmd
.
The file name should be short but meaningful. This is important when dealing with a lot of files, like for a website. So add relevant details but keep it less than 25 characters—long file names mean long URLs, which can increase the likelihood of errors..
If you include a date in the name, use date format ISO_8601
YYYY-MM-DD
or YYYYMMDD
. Distill blog sites use
YYYY-MM-DD
by default.
You can begin a file/directory name with a number, just be sure to
use sequential numbering like 01_File
,
02_Stuff
, etc. instead of 1_File
and
2_Stuff
.
Whatever approach you choose, I think the main key is to be
consistent. If you use dashes -
to separate words in a
name, then try to stick with that for everything.
The feature photo for this post—A small amateur insect collection by Debivort at the English-language Wikipedia—was retrieved from Wikimedia Commons and Licensed under CC BY-SA 3.0. Original image found here.
The source code for this page can be accessed on GitHub by clicking this link.
If you see mistakes or want to suggest changes, please create an issue on the source repository.
Text and figures are licensed under Creative Commons Attribution CC BY-SA 4.0. Source code is available at https://github.com/stri-mcgill-neo/2022/, unless otherwise noted. The figures that have been reused from other sources don't fall under this license and can be recognized by a note in their caption: "Figure from ...".