Function Repository Resource:

FileQ

Source Notebook

Test if a file exists

Contributed by: Taliesin Beynon

ResourceFunction["FileQ"][path]

returns True if path exists and is an ordinary file.

Details and Options

ResourceFunction["FileQ"] does not recognize directories.

Examples

Basic Examples (3) 

Export a plot as a GIF:

In[1]:=
Export["test.gif", Plot[Sin[x], {x, 0, 10}]]
Out[1]=
In[2]:=
ResourceFunction["FileQ"][%]
Out[2]=

Create an empty file:

In[3]:=
Put[FileNameJoin[{$TemporaryDirectory, "temp.txt"}]]
In[4]:=
ResourceFunction["FileQ"][
 FileNameJoin[{$TemporaryDirectory, "temp.txt"}]]
Out[4]=

Find a file:

In[5]:=
FileNames[$InstallationDirectory <> "/*"]
Out[5]=
In[6]:=
ResourceFunction["FileQ"] /@ %
Out[6]=

Possible Issues (1) 

FileQ does not work with directories:

In[7]:=
filename = CreateDirectory[];
In[8]:=
ResourceFunction["FileQ"][filename]
Out[8]=
In[9]:=
FileExistsQ[filename]
Out[9]=
In[10]:=
FileType[filename]
Out[10]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Version History

  • 1.0.0 – 17 December 2018

License Information