Navigating a directory tree

A program must read orders.csv from the data directory (folder) in Listing 1. You run the program from /course/exercises. This folder is its current working directory, the starting point for relative paths.

Paths use / to separate names. A leading / means the root directory, the top-level folder containing everything in this tree. All entries shown are ordinary files or directories in a fictional file system. No files need to exist on your computer.

Listing 1: Directories and files available to the program.
/                       # Root: start of an absolute path.
└── course/
    ├── data/
    │   └── orders.csv
    └── exercises/      # You are here: /course/exercises.
        ├── notes.txt
        └── reports/
            └── summary.csv

Which pair gives an absolute path and a relative path that both identify the required file? Each choice gives the absolute path first and the relative path second.

  • /course/data/orders.csv and data/orders.csv.
  • /course/data/orders.csv and ../data/orders.csv.
  • /course/exercises/data/orders.csv and ../data/orders.csv.
  • /data/orders.csv and ../../data/orders.csv.
  • A path starting with / is interpreted from the root. A path without a leading / is interpreted from the current working directory.
  • .. moves to the parent directory; a directory name moves into that child directory. For example, from /lab/tasks, ../input identifies /lab/input.
  • A filename at the end selects a file inside the preceding directory.