FileNameDepth

FileNameDepth["name"]

gives the number of path elements in the file name "file".

Details and Options

  • FileNameDepth["a/b/c"] gives 3.
  • FileNameDepth by default assumes pathname separators and other conventions suitable for your operating system.
  • FileNameDepth[,OperatingSystem->"os"] uses the conventions of the specified operating system. Possible choices are "Windows", "MacOSX", and "Unix".
  • FileNameDepth just operates on names of files; it does not actually search for the file specified.
  • FileNameDepth[File["name"]] is also supported.

Examples

open allclose all

Basic Examples  (3)

Find the number of path elements that make up a file name:

File name depths of some standard directories:

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

Scope  (1)

Find the number of path elements in the file name specified by the File object:

Introduced in 2008
 (7.0)
 |
Updated in 2016
 (11.0)