DirectoryName
DirectoryName["name"]
extracts the directory name from the specification for a file.
Details and Options
- DirectoryName works differently on different computer systems.
- DirectoryName["directory"] is normally equivalent to ParentDirectory["directory"].
- DirectoryName["name",n] applies DirectoryName n times to name.
- DirectoryName yields output appropriate for use in SetDirectory and FileNameJoin.
- If name contains no directory specification, DirectoryName["name"] returns "".
- DirectoryName by default uses pathname separators and other conventions suitable for your operating system.
- DirectoryName[…,OperatingSystem->"os"] uses the conventions of the specified operating system. Possible choices are "Windows", "MacOSX", and "Unix".
- DirectoryName[File["name"]] is also supported.
Examples
open allclose allBasic Examples (1)
Get the directory name of a file on Windows:
Get the directory name of a file on Mac OS X:
Apply DirectoryName two times:
Scope (1)
Get the directory name of a file specified as a File object:
Text
Wolfram Research (1996), DirectoryName, Wolfram Language function, https://reference.wolfram.com/language/ref/DirectoryName.html (updated 2016).
CMS
Wolfram Language. 1996. "DirectoryName." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2016. https://reference.wolfram.com/language/ref/DirectoryName.html.
APA
Wolfram Language. (1996). DirectoryName. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/DirectoryName.html