Paths: how to name any file
Artifact: Writing the full path of any file, and telling absolute from relative
1. The promise
You'll be able to write the full path of any file on your machine, tell an absolute path from a relative one, and know why / and \ are different and which one your system uses.
2. The mental model
A path is the instructions to walk through the tree to a specific file.
- An absolute path starts at the root. Like giving directions from the central station: "from the station, take the train to Brunswick, walk three blocks east, second door."
- A relative path starts wherever you happen to be right now. Like giving directions from the coffee shop you're already at: "two doors down, on the left."
The vocabulary, said properly:
- A path is a string that names a file by giving the route through the folder tree.
- An absolute path starts at the root (
/orC:\). - A relative path is interpreted from a current location.
- The parent folder is the folder one level up. Written as
..(two dots). - The current folder is the folder you're in. Written as
.(one dot). - The home shortcut
~(tilde) means your user's home folder. macOS and Linux always understand it; modern Windows PowerShell does too. - The path separator is the character between folder names.
/on macOS and Linux.\on Windows.
(DIAGRAM: anatomy of a path — annotated SVG — /Users/yourname/Documents/notes.txt split into labelled segments: root, user-folder, subfolder, filename)
Try it before you read
Without looking ahead — what's the absolute path of a file called `resume.pdf` in your Documents folder, on macOS or Linux?
(DIAGRAM: absolute vs relative — annotated SVG — same target file, two arrows: one from root labelled "absolute /Users/yourname/Documents/notes.txt", one from a "current location" labelled "relative ./Documents/notes.txt")
3. You do it, with me
We're going to read paths off your own machine and write three down.
Step 1. Pick any file in your Documents folder. A .docx, a .pdf, the hello.txt you made in unit 0.4. Anything.
Step 2. Copy its full path.
- macOS: right-click the file -> hold
Option-> the menu item changes from "Copy" to "Copyfilenameas Pathname". Click it.
(SCREENSHOT: macOS right-click menu with Option held — showing "Copy notes.txt as Pathname" — highlighted)
- Windows: hold
Shift, right-click the file -> "Copy as path".
(SCREENSHOT: Windows File Explorer right-click menu with Shift held — showing "Copy as path" — highlighted)
Step 3. Paste it into TextEdit or Notepad. You'll see something like:
- macOS:
/Users/yourname/Documents/notes.txt - Windows:
"C:\Users\yourname\Documents\notes.txt"(Windows adds quotes)
(SCREENSHOT: macOS Get Info for notes.txt — full window — "Where" field highlighted)
(SCREENSHOT: macOS Finder address bar with full path visible (after View -> Show Path Bar) — full window)
(SCREENSHOT: Windows File Explorer address bar with full path visible — full window — the address bar highlighted)
Step 4. Walk through the path left to right. Take /Users/yourname/Documents/notes.txt apart:
/— the root.Users— a folder inside the root.yourname— your home folder, insideUsers.Documents— a folder inside your home.notes.txt— the file itself.
Read it out loud. "Root, Users, your name, Documents, notes-dot-txt." Do this once and the shape sticks.
Step 5. Do steps 2 to 4 for two more files. Pick one in Downloads and one on the Desktop. Paste all three paths into the same TextEdit or Notepad window.
(SCREENSHOT: a text file containing the three pasted paths — TextEdit or Notepad — full window)
Step 6. Try the dots. From the path /Users/yourname/Documents/notes.txt:
..fromDocumentsmeans/Users/yourname/.../Downloads/fromDocumentsmeans/Users/yourname/Downloads/. Up one level, then into Downloads..meansDocumentsitself.
You won't type these in the file manager. You'll type them constantly in the terminal in Ch 2 and in code from Ch 4 onwards.
Step 7. The home shortcut. Instead of /Users/yourname/Documents, you can write ~/Documents. The OS expands ~ to your home folder. This works on macOS, on Linux, and in modern Windows PowerShell.
Step 8. The separator difference. macOS and Linux use /. Windows uses \. When you write JavaScript later (Ch 6), URLs and many APIs use / even on Windows. Don't fight it — prefer / in code, even on a Windows machine, except when you're talking to Windows-only tools.
4. What you should be seeing
A text file with three absolute paths from your machine, each starting at / or C:\. You can read each one out loud and name each segment.
You can also write the relative path from Documents to a file in Downloads: ../Downloads/filename. Up one, into Downloads, file name.
5. Common stumbles
- You wrote the path with the wrong separator. Backslashes on macOS, forward slashes on Windows when talking to a Windows-only tool. The fix is always to copy the path from the file manager, never type it from memory.
- You forgot the leading
/orC:\and the path is relative when you meant absolute. Absolute paths always start at the root. If your path starts with a folder name, it's relative. - Spaces in folder names bite.
My Documentshas a space. In code or in the terminal, that space looks like the end of one argument and the start of another. The fix is to wrap the whole path in quotes:"My Documents". We come back to this in Ch 2. - The terminal's "current folder" feels mysterious. It isn't. It's the same idea as "the folder File Explorer is currently showing" — just text instead of a window. Every relative path is read from there.