FileNameDepth

FileNameDepth["file"]
gives the number of path elements in the file name .

Details and OptionsDetails and Options

  • FileNameDepth["a/b/c"] gives .
  • 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 , , and .
  • FileNameDepth just operates on names of files; it does not actually search for the file specified.

ExamplesExamplesopen allclose all

Basic Examples (3)Basic Examples (3)

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

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=

File name depths of some standard directories:

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=
In[3]:=
Click for copyable input
Out[3]=

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

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=
New in 7
New to Mathematica? Find your learning path »
Have a question? Ask support »