gives the last path element in the file name "name".


gives the first n path elements in the file name "name".


gives the last n path elements in the file name "name".


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.


open allclose all

Basic Examples  (4)

Extract the last path element from a file name:

Get different path elements in a file name:

Find out where the Wolfram System is installed:

On Windows, the share name is treated as a single unit:

Scope  (1)

Extract a path element from the file name specified by the File object:

Introduced in 2008
Updated in 2016