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 allclose allBasic Examples (3)
Get the parent directory of the current working directory:
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:
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:
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