2.1. File Paths#
A file path is like an address to a file. There are generally two types, absolute and relative. Most of our activities focus on working in a working directory, so we will focus almost entirely on relative paths. The general format is like this:
./subdirectory_1/subdir_2/filename.ext
where:
the dot
.indicates one should use the current directory of the file (or the CLI) as the current location (the.is like saying “ start here”)forward slashes
/separate subdirectoriesthe last two words are the file name and extension. For example, common image extensions are
.jpg,.pngor.svgin this example, the image file is stored inside a folder called
subdir_2which is inside a folder calledsubdirectory_1which is in our working directory.Do not include spaces in your file path or file names; if it is unavoidable replace the space with
%20, for example:
As a general rule, always use forward slashes whenever possible. Although backward slashes are the default and must be used at times on Windows, they don’t work on Mac or Linux systems. This causes problems when sharing code with others running these systems. Remember that we try to do things in a way that allows easy collaboration: using approaches that are agnostic of the operating system (i.e., works on all platforms). This is hard to guarantee in practice, but consistently using forward slashes will get us close!
Attribution
This chapter is written by Robert Lanzafame and Tom van Woudenberg. Find out more here.