ParentDirectory

ParentDirectory[]

gives the parent of the current working directory.

ParentDirectory["dir"]

gives the parent of the directory dir.

ParentDirectory["dir",n]

gives the directory n levels up from dir.

Details

Examples

open allclose all

Basic Examples  (3)

Get the parent directory of the current working directory:

Verify the answer:

Get the parent of $InstallationDirectory:

Find the grandparent of $InstallationDirectory:

Scope  (3)

Get the parent directory of the directory specified by the File object:

Go up two levels from the same location:

Go up two levels from the current directory:

Compare with the current directory:

Explicitly request the directory one level higher than the current directory:

This is equivalent to the following:

Properties & Relations  (4)

In ParentDirectory[dir], dir must exist as a directory:

ParentDirectory always returns a full path:

ParentDirectory[1] is equivalent to ParentDirectory[]:

ParentDirectory operates only on existing directories and returns a full path:

FileNameDrop performs a similar path operation but at a purely textual level:

Introduced in 1991
 (2.0)
 |
Updated in 2016
 (11.0)
2017
 (11.2)