Paths & Directories

MCS 260 Fall 2021

Week 1 Discussion

Files and Directories

A file is a named collection of data (e.g. a document). Files cannot contain other files.

A directory or folder is a named container for both files and directories.

Full paths

Multiple files may share the same name. To specify a file, you also need to know what directory it is in.

A full path does this. It specifies the file name and all the directories containing it.

Example (Windows):


Example (Linux/OS X):


Decoding a full path

Consider the Windows example:


"C:" is the drive letter (specifies a storage device)

"\" is a separator (appears between directory names and file names)

"Users", "sramanujan", "Documents" are directories, each contained within the previous one

"letter.pdf" is the filename

The Desktop is just a directory

Icons on the desktop are just files in a certain directory.

In Windows, the desktop directory for a user named "ddumas" is usually:


In OS X, it is usually:


In Linux, it is usually:



This file on professor Dumas's desktop:

Has full path:


So one way to run it in Powershell would be:

        python C:\Users\ddumas\Desktop\

Current working directory

Terminal interfaces and some other programs have a notion of the current working directory.

There is a command to show the current directory in a terminal:


(print working directory)

Important: In a terminal, filenames without a full path are assumed to refer to files in the current directory.

A common mistake

In Powershell, this command will probably fail:


It only looks in the current directory for a file named "". If a file with that name exists but is in a different directory, it will not be found.

To fix this, you have two choices:

  • Replace "" with a full path
  • Change the current working directory to the one that contains

Changing the current working directory

Move to another directory given by a full path:

        cd C:\Users\ddumas\Desktop

Move to another directory that is contained in the current one (a subdirectory):

        cd Desktop

Move to the parent directory, i.e. the one that contains the current one:

        cd ..

Running a script: three ways

We want to run, a script on the desktop.

In PowerShell, with absolute path:

PS C:\Users\ddumas> python C:\Users\ddumas\Desktop\
Hello world

In PowerShell, first cd to Desktop, then run:

PS C:\Users\ddumas> cd Desktop
PS C:\Users\ddumas\Desktop> python
Hello world

In PowerShell, with relative path:

PS C:\Users\ddumas> python Desktop\
Hello world

Where is my file?

If you have a file open in Visual Studio Code, you can ask for its full path to be copied to the clipboard.

Right-click on the file name tab and select "Copy path".