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.
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
- ParentDirectory returns the full name of the directory as a string.
- If n is an integer, ParentDirectory[n] gives the directory n levels up from the current directory.
- ParentDirectory[File["dir"],…] is also supported.
Examples
open all close allBasic Examples (3)
Get the parent directory of the current working directory:
ParentDirectory[]Directory[]Get the parent of $InstallationDirectory:
ParentDirectory[$InstallationDirectory]Find the grandparent of $InstallationDirectory:
ParentDirectory[$InstallationDirectory, 2]Scope (3)
Get the parent directory of the directory specified by the File object:
ParentDirectory[File[$InstallationDirectory]]Go up two levels from the same location:
ParentDirectory[File[$InstallationDirectory], 2]Go up two levels from the current directory:
ParentDirectory[2]Compare with the current directory:
Directory[]Explicitly request the directory one level higher than the current directory:
ParentDirectory[1]This is equivalent to the following:
ParentDirectory[]Properties & Relations (4)
In ParentDirectory[dir], dir must exist as a directory:
ParentDirectory["/IDoNotExist"]ParentDirectory always returns a full path:
ParentDirectory[".."]ParentDirectory[1] is equivalent to ParentDirectory[]:
ParentDirectory[] === ParentDirectory[1]ParentDirectory operates only on existing directories and returns a full path:
ParentDirectory[$HomeDirectory]FileNameDrop performs a similar path operation but at a purely textual level:
FileNameDrop["~/IDontExist", -1]See Also
Tech Notes
Related Guides
Related Workflows
- Construct a File Path Programmatically
History
Introduced in 1991 (2.0) | Updated in 2016 (11.0) ▪ 2017 (11.2)
Text
Wolfram Research (1991), ParentDirectory, Wolfram Language function, https://reference.wolfram.com/language/ref/ParentDirectory.html (updated 2017).
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
BibTeX
@misc{reference.wolfram_2026_parentdirectory, author="Wolfram Research", title="{ParentDirectory}", year="2017", howpublished="\url{https://reference.wolfram.com/language/ref/ParentDirectory.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_parentdirectory, organization={Wolfram Research}, title={ParentDirectory}, year={2017}, url={https://reference.wolfram.com/language/ref/ParentDirectory.html}, note=[Accessed: 13-June-2026]}