User Guide Cancel

FileExists

 

Description

Determines whether an on-disk or in-memory file exists.

Returns

Yes, if the file specified in the parameter exists; No, otherwise.

Category

System functionsDecision functions

Function syntax

FileExists(absolute_path)

See also

DirectoryExistsExpandPathGetTemplatePath

Parameters

Parameter

Description

absolute_path

The absolute path of the on-disk or in-memory file.

Usage

To access a file on a remote system, the account (for Windows) or user (for UNIX and Linux) that is running ColdFusion must have permission to access the file, directory, and remote system. For example, if you run ColdFusion in the Server Configuration as a Windows service, by default it runs under the local system account, which does not have sufficient privileges to access remote systems. You can change this, however, on the Log On page of the Services Properties dialog box.

Example

<cfscript>
theDir=GetDirectoryFromPath(GetCurrentTemplatePath());
theFile=theDir & "Sample files/IsValid2.cfm";
fileExist = FileExists(theFile);
writeoutput("Does the file exists" & "<br>" & fileExist);
</cfscript>
<cfscript> theDir=GetDirectoryFromPath(GetCurrentTemplatePath()); theFile=theDir & "Sample files/IsValid2.cfm"; fileExist = FileExists(theFile); writeoutput("Does the file exists" & "<br>" & fileExist); </cfscript>
<cfscript>
theDir=GetDirectoryFromPath(GetCurrentTemplatePath()); 
theFile=theDir & "Sample files/IsValid2.cfm";
fileExist = FileExists(theFile);
writeoutput("Does the file exists" & "<br>" & fileExist);
</cfscript>

Output

Does the file exist
YES

Get help faster and easier

New user?