FileNameTake["name"]
gives the last path element in the file name "name".
FileNameTake["name",n]
gives the first n path elements in the file name "name".
FileNameTake["name",-n]
gives the last n path elements in the file name "name".
FileNameTake["name",{m,n}]
gives elements m through n in the file name "name".
FileNameTake
FileNameTake["name"]
gives the last path element in the file name "name".
FileNameTake["name",n]
gives the first n path elements in the file name "name".
FileNameTake["name",-n]
gives the last n path elements in the file name "name".
FileNameTake["name",{m,n}]
gives elements m through n in the file name "name".
Details and Options
- FileNameTake by default assumes that path elements are separated by pathname separators suitable for your operating system.
- FileNameTake[…,OperatingSystem->"os"] uses the conventions of the specified operating system. Possible choices are "Windows", "MacOSX", and "Unix".
- FileNameTake just operates on names of files; it does not actually search for the file specified.
- If more elements are requested than are present, FileNameTake just gives those that are present.
- FileNameTake[File["name"],…] is also supported.
Examples
open all close allBasic Examples (4)
Extract the last path element from a file name:
FileNameTake["/a/b/c.txt"]Get different path elements in a file name:
path = FileNameJoin[{"a", "b", "c", "d", "e"}]FileNameTake[path, 1]FileNameTake[path, -1]FileNameTake[path, {2, 3}]Find out where the Wolfram System is installed:
FileNameTake[$InstallationDirectory, {1, -1}]On Windows, the share name is treated as a single unit:
FileNameTake["\\\\server\\share\\path\\file", 1]Scope (1)
Extract a path element from the file name specified by the File object:
file = File[FileNameJoin[{"a", "b", "c"}]]FileNameTake[file, -1]Related Guides
Related Workflows
- Construct a File Path Programmatically
Text
Wolfram Research (2008), FileNameTake, Wolfram Language function, https://reference.wolfram.com/language/ref/FileNameTake.html (updated 2016).
CMS
Wolfram Language. 2008. "FileNameTake." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2016. https://reference.wolfram.com/language/ref/FileNameTake.html.
APA
Wolfram Language. (2008). FileNameTake. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/FileNameTake.html
BibTeX
@misc{reference.wolfram_2026_filenametake, author="Wolfram Research", title="{FileNameTake}", year="2016", howpublished="\url{https://reference.wolfram.com/language/ref/FileNameTake.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_filenametake, organization={Wolfram Research}, title={FileNameTake}, year={2016}, url={https://reference.wolfram.com/language/ref/FileNameTake.html}, note=[Accessed: 13-June-2026]}