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:

Wolfram Research (1991), ParentDirectory, Wolfram Language function, https://reference.wolfram.com/language/ref/ParentDirectory.html (updated 2017).

Text

Wolfram Research (1991), ParentDirectory, Wolfram Language function, https://reference.wolfram.com/language/ref/ParentDirectory.html (updated 2017).

BibTeX

@misc{reference.wolfram_2020_parentdirectory, author="Wolfram Research", title="{ParentDirectory}", year="2017", howpublished="\url{https://reference.wolfram.com/language/ref/ParentDirectory.html}", note=[Accessed: 14-May-2021 ]}

BibLaTeX

@online{reference.wolfram_2020_parentdirectory, organization={Wolfram Research}, title={ParentDirectory}, year={2017}, url={https://reference.wolfram.com/language/ref/ParentDirectory.html}, note=[Accessed: 14-May-2021 ]}

CMS

Wolfram Language. 1991. "ParentDirectory." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2017. https://reference.wolfram.com/language/ref/ParentDirectory.html.

APA

Wolfram Language. (1991). ParentDirectory. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ParentDirectory.html