FileExistsQ

FileExistsQ["name"]
gives True if the file with the specified name exists, and gives False otherwise.

DetailsDetails

  • In FileExistsQ["name"], name is interpreted relative to your current directory.
  • FileExistsQ does not search $Path.
  • FileExistsQ tests for files, directories or any other filesystem objects.

ExamplesExamplesopen allclose all

Basic Examples (2)Basic Examples (2)

Check if a file exists:

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

Create a file:

In[1]:=
Click for copyable input

Check if the file exists:

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

Delete the file:

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