0%

Files, Folders, and Paths

Read a Path One Part at a Time

A tree is easy to read when someone draws it for you. Software does not get a drawing. It gets a line of text, and that line has to contain the entire route.

That written route is a path.

Here is the way to observations.csv on a Windows machine:

C:\Users\Sam\Documents\field-notes\data\observations.csv

Read it left to right and it is a set of directions:

  1. Start at the C:\ drive root.

  2. Go into Users.

  3. Then Sam, then Documents, then field-notes.

  4. Then data.

  5. Stop at the file observations.csv.

Each named step is a path segment, and Windows conventionally separates them with a backslash.

The same project on :

/home/sam/Documents/field-notes/data/observations.csv

The leading / is the filesystem root. The rest separate the segments home, sam, Documents, field-notes, data, and observations.csv.

And on :

/Users/sam/Documents/field-notes/data/observations.csv

The three spellings differ, but the reasoning behind them does not: find the starting point, then follow one segment at a time until you reach the target.

Separators are not part of names

A separator marks a boundary. It belongs to neither neighbor. The Windows directory in that path is named data, not \data and not data\.

Segments can contain spaces, hyphens, and dots. In this path, project notes.txt is one filename that happens to have a space in the middle:

C:\Users\Sam\Documents\field-notes\project notes.txt

Hold onto that one. When you get to a , that space causes real trouble and quotation marks fix it. The quotes will be there to help the shell split the line correctly, and they are never part of the filename.

Which item is one path segment in /home/sam/Documents/field-notes/data/observations.csv?

Diagnose a path before you change anything

“That path does not exist” is one of the most common messages you will ever see, and the instinct it produces is usually wrong. People start adding slashes, or moving files around, and turn one problem into three.

Compare the path against the tree, one segment at a time, looking for these five:

  • Wrong starting point. C:\ and / are different worlds. A Windows path pasted into a macOS application names nothing at all.

  • Missing or repeated segment. field-notes\data\data\observations.csv enters data twice. You will not spot this by scanning the whole string; you spot it by walking it.

  • Name mismatch. observation.csv and observations.csv are different files. Some common filesystems ignore letter case by default; others distinguish Report.txt from report.txt. Copy the exact spelling and capitalization you see so the same path works in either place.

  • Hidden extension. A file displayed as observations.csv might really be observations.csv.txt.

  • Wrong separator. Windows shows \, uses /. Some Windows tools accept both, which is a convenience rather than a reason to rewrite paths at random.

Find the first segment that does not match the tree. Everything past that point is unreachable, and that segment is the only thing worth fixing.

The tree is field-notes/ containing data/ containing raw/. An application reports it cannot open field-notes/data/raw/notes/monday.txt. Which segment should you investigate first?

You can now move between a tree and a written route on all three platforms. One question is still open, and it turns out to matter enormously: does a path start at a root, or does it start wherever you happen to be standing?