Folder hierarchy and file paths

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

This Folder hierarchy and file paths worksheet is part of the WA Computer Science ATAR Year 11 — Network Communications journey. Print it as a booklet?

Folder hierarchy and file paths

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which is an absolute path on a Windows computer?
A C:\Users\Sam\file.txt
B Sam\file.txt
2. Which is an absolute path on a Linux computer?
A /home/sam/file.txt
B sam/file.txt
3. A relative path is written from...
A The root of the drive
B The current folder
4. You are in /home/sam. Which relative path points to /home/sam/docs/file.txt?
A docs/file.txt
B /docs/file.txt
5. What does .. mean in a relative path such as ../file.txt?
A Go down into a new subfolder
B Go up one folder to the parent

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1C:\Users\Sam\file.txt AA relative path starts at the current folder, so from inside docs it looks for docs/docs/report.txt, which does not exist.
2/home/sam/file.txt Bdocs/report.txt
3A relative path locates a file starting from the current folder, not from the root CThe .. means go up one folder, so the path leads to /home/sam/file.txt, not into the docs folder.
4A network drive path locates a file on another computer using the server name and a shared folder DAn absolute Windows path starting at the C: drive root and going down through the Users and Sam folders to file.txt
5/home/sam/docs/../file.txt typed as the path to docs/file.txt EAn absolute Linux path starting at the root / and going through the home and sam folders to file.txt
6Using the relative path docs/report.txt from inside the docs folder F\\server\shared\file.txt

Definitions

file path

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
__\Users\Sam\file.txt
2.
_home/sam/file.txt
3.
__/notes/file.txt
4.
__server\share\file.txt
5.
cd /home/sam cat _/file.txt

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A cd \home\sam
B ls
C cat file.txt
Question 2
A cd /home/sam
B mkdir school
C cd school
D cat ./file.txt
Question 3
A import os
B base = "/home/sam"
C path = base + "a.txt"
D print(path)
Question 4
A cd C:\Users\Sam
B cd \Documents
C type file.txt
Question 5
A net use Z: \fileserver\share
B cd Z:\reports
C type budget.txt

Answer Key

Folder hierarchy and file paths
Section A: Quick Questions
Q1
A — C:\Users\Sam\file.txt
Q2
A — /home/sam/file.txt
Q3
B — The current folder
Q4
A — docs/file.txt
Q5
B — Go up one folder to the parent
Section B: Match the Pairs
Q1
C:\Users\Sam\file.txt → An absolute Windows path starting at the C: drive root and going down through the Users and Sam folders to file.txt
Q2
/home/sam/file.txt → An absolute Linux path starting at the root / and going through the home and sam folders to file.txt
Q3
A relative path locates a file starting from the current folder, not from the root → docs/report.txt
Q4
A network drive path locates a file on another computer using the server name and a shared folder → \\server\shared\file.txt
Q5
/home/sam/docs/../file.txt typed as the path to docs/file.txt → The .. means go up one folder, so the path leads to /home/sam/file.txt, not into the docs folder.
Q6
Using the relative path docs/report.txt from inside the docs folder → A relative path starts at the current folder, so from inside docs it looks for docs/docs/report.txt, which does not exist.
Section C: Definitions
Q1
file path — The location of a file in the folder tree, written from the root (absolute, e.g. /home/sam/file.txt) or from the current folder (relative).
Section D: Fill in the Blanks
Q1
C:\Users\Sam\file.txt
Q2
/home/sam/file.txt
Q3
../notes/file.txt
Q4
\\server\share\file.txt
Q5
cd /home/sam cat ./file.txt
Section E: Spot the Error
Q1
A — Linux paths use forward slashes. The absolute path to the folder is /home/sam, not \home\sam.
Q2
D — ./ means the current folder (school), but file.txt is in /home/sam. The relative path must use ../ to go up one folder: cat ../file.txt.
Q3
C — Without a / separator the result is /home/sama.txt. The folder and file name must be joined with a slash: base + "/a.txt".
Q4
B — A leading backslash starts from the root of the drive, so this looks for C:\Documents. A relative path from C:\Users\Sam is just Documents.
Q5
A — A Windows network drive path (UNC path) starts with two backslashes: \\fileserver\share. A single backslash is not a network location.