Function Resource

FileQ

Determine if the argument is a file, or not

ResourceFunction["FileQ"][name]

gives True if name is a file, and False otherwise.

Examples

Basic Examples

Select a known existing file from the system layout, for example the root guide page:

In[1]:=
file = FileNameJoin[{$InstallationDirectory, "Documentation", $Language, "System", "Guides", "WolframRoot.nb"}]
Out[1]=

Check that it is indeed a file:

In[2]:=
ResourceFunction[ "https://www.wolframcloud.com/obj/arnoudb/DeployedResources/Function/\
FileQ"][file]
Out[2]=

A directory is not a file:

In[3]:=
ResourceFunction[ "https://www.wolframcloud.com/obj/arnoudb/DeployedResources/Function/\
FileQ"][$InstallationDirectory]
Out[3]=

FileQ returns False for files that do not exist:

In[4]:=
ResourceFunction[ "https://www.wolframcloud.com/obj/arnoudb/DeployedResources/Function/\
FileQ"][FileNameJoin[{$InstallationDirectory, "does-not-exist.txt"}]]
Out[4]=

Scope

Create a list whose elements contain directories and files:

In[5]:=
list = FileNames["*", $InstallationDirectory, \[Infinity]];

Check how many elements the list has:

In[6]:=
Length[list]
Out[6]=

Check how many elements are files:

In[7]:=
Select[list, ResourceFunction[ "https://www.wolframcloud.com/obj/arnoudb/DeployedResources/\
Function/FileQ"]] // Length
Out[7]=