Module 18 · Files, Folders and Delete

How do you tell a computer exactly where a file is?

Lesson 18.2 · Paths

Sarah · Jenny · Rob

Two blocks back, or the full address.

Sarah is deep inside the Recipes folder and wants to get to the photos.

Jenny says she can climb back up one folder at a time, or she can give the whole address at once, starting from the top.

Rob says that’s like giving directions as “two blocks back” versus a full street address.

The short answer

With a path: the folders from the top down to the file, like /home/ruth/Pictures/captions.txt. Sarah climbed up with .., jumped across with a full path and found out the cat is named Mittens. The photos are backed up next.

Try it yourself

Get from the recipes to the cat photos.

1 of 4 Go up one folder.

Try: pwd, ls, cd <folder>, cd .., cat <file>

/home/ruth/Documents/Recipes $

What you just did has a name

A file path

A file path is a file’s address: the list of folders you go through to reach it, separated by slashes.

A full path, or absolute path, starts from the top, like /home/ruth/Pictures/captions.txt, and works from anywhere.

A relative path starts from where you are, and “..” means the folder above.

Windows writes paths with backslashes and drive letters, like C:\Users\Ruth\Pictures, but the idea is the same.

A few more things

Copy the path

In File Explorer you can click the address bar to see and copy a folder’s full path. On a Mac, Finder can show a path bar at the bottom.

Web addresses are paths too

In pettigrewlab.com/learn/how-computers-work, the parts after the first slash are a path on the web server. Module 22 picks that up.

Why the command line is handy

Typing a path can be faster than clicking through six folders, and one command can work on a thousand files at once.

Go deeper

The longer version, if you want it.

Why spaces cause trouble

On a command line, spaces separate a command from what it works on. So a file named “my recipe.txt” looks like two things: “my” and “recipe.txt.” You have to wrap the name in quotes or use dashes instead.

That’s why programmers name files like apple-pie.txt. It’s a small habit that saves a lot of annoyance.

Quick check

You’re in /home/ruth/Documents and type cd .. Where do you end up?

Let’s take it slower

Directions to a friend’s house can be “go back to the corner, then left” or “123 Main Street.” The first only works if you know where you’re standing. The second works from anywhere. A relative path is the first kind. A full path is the street address.

More examples

1

Saving a file

When an app asks where to save, the folder you pick becomes the start of the file’s path.

2

The desktop shortcut that stopped working

Someone moves a spreadsheet into a different folder, and the shortcut on their desktop suddenly says the file can’t be found. The shortcut only remembered the old path. The file is fine. Its address changed.

Back to the question

So how do you tell a computer exactly where a file is?

Show the answer

With a path: the folders from the top down to the file, like /home/ruth/Pictures/captions.txt. Sarah climbed up with .., jumped across with a full path and found out the cat is named Mittens. The photos are backed up next.

One last question

Which of these would you trust?

“A full path starts from the top folder and works from anywhere.”

“Two dots in a path mean the folder above.”

“Two files can have the same full path.”

“Windows has no file paths.”

Talk Card

Talk Card · 18.2

Every file has exactly one full address, from the top folder down, like a street address for Grandma Ruth’s apple pie recipe.

How Computers Work · pettigrewlab.com/learn

Next lesson