File Paths#

File Systems#

Computers use a hierarchical file systems that organizes files & folders.

When you click through the folders (directories) on your computer, you’re interacting with this hierarchical system.

File Paths#

The specific location of a file or folder on your computer.

When using a Graphical User Interface (GUI), you click on directories to access subdirectories and finally find the file you’re interested in.

When using the command line, you specify a file’s path explicitly with text.

Absolute vs. Relative Paths#

There are two ways to specify the path to your file of interest allow for flexibility in programming. Using absolute paths and using relative paths.

Absolute Paths#

Absolute paths specify the full path for a given file system (starting from the root directory).

root specifies the ‘highest’ directory in the file structure (the start).

An absolute file path starts with a slash / specifying the root directory.

The absolute path to A2.ipynb would be:

/Teaching/COGS18/A2.ipynb

  • initial forward slash indicates root directory

  • Teaching is in root

  • COGS18 is in taeching

  • file is in COGS 18

Relative Paths#

Relative paths specify the path to a file from your current working directory (where your computer is working right now).

The computer keeps track of your current working directory.

If your current working directory were Teaching…and you wanted to access the A2.ipynb file in COGS 18, you could use the relative path:

COGS18/A2.ipynb

Notes:

  • No leading slash indicating a relative path

  • Path is specified relative to current location