View comments | RSS feed
Contents > CFML Reference > ColdFusion Functions > FileExists PreviousNext

FileExists

Determines whether a file exists.

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

System functions, Decision functions

FileExists(absolute_path)

DirectoryExists, ExpandPath, GetTemplatePath

Parameter

Description

absolute_path

An absolute path

<h3>FileExists Example</h3>

<cfset thisPath = ExpandPath("*.*")>
<cfset thisDirectory = GetDirectoryFromPath(thisPath)>
<cfoutput>
The current directory is: #GetDirectoryFromPath(thisPath)#
<cfif IsDefined("FORM.yourFile")>
<cfif FORM.yourFile is not "">
<cfset yourFile = FORM.yourFile>
   <cfif FileExists(ExpandPath(yourfile))>
   <p>Your file exists in this directory. You entered
   the correct file name, #GetFileFromPath("#thisPath#/#yourfile#")#
   <cfelse>

Contents > CFML Reference > ColdFusion Functions > FileExists PreviousNext

ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6.1

Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.

Comments


matthewmazurek said on Jan 24, 2004 at 10:00 PM :
this works fine locally but creates some problems when i try it on the remote server. does fileexist only work for local files?
halL said on Jan 27, 2004 at 9:53 AM :
The account (for Windows) or user (for UNIX and Linux) that is runnig ColdFusion must have permission to access the file, directory and remote system.
For example, if you run ColdFusion MX in the Server Configuration as a Windows service, by default it runs under the local system account, which does not have sufficient rights to access remote systems.
(You can change this in the service properties dialog Log On page.)
octupii said on Feb 4, 2005 at 2:47 PM :
on a shared server, I received the following error trying to check for the existence of an image file:

Security: The requested template has been denied access to images\products\thumbs\offi\zumiStool.gif.
The following is the internal exception message: access denied (java.io.FilePermission images\products\thumbs\offi\zumiStool.gif read)

The error occurred in D:\FTP\twojakes\Htdocs\dev.cfm: line 70

68 : <cfoutput QUERY="intro">
69 : <a href="##_#itemoid#">
70 : <cfif FileExists("images/products/thumbs/#image#")>
71 : <img src="images/products/thumbs/#image#" border="0">
72 : <cfelse>

Please try the following:

* Check the ColdFusion documentation to verify that you are using the correct syntax.
* Search the Knowledge Base to find a solution to your problem.

Browser Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1
Remote Address 70.19.90.176
Referrer
Date/Time 04-Feb-05 02:34 PM
Stack Trace
at cfdev2ecfm1995185587.runPage(D:\FTP\twojakes\Htdocs\dev.cfm:70)

java.security.AccessControlException: access denied (java.io.FilePermission images\products\thumbs\offi\zumiStool.gif read)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:269)
at java.security.AccessController.checkPermission(AccessController.java:401)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:524)
at java.lang.SecurityManager.checkRead(SecurityManager.java:863)
at java.io.File.isFile(File.java:723)
at coldfusion.runtime.CFPage.FileExists(CFPage.java:3239)
at cfdev2ecfm1995185587.runPage(D:\FTP\twojakes\Htdocs\dev.cfm:70)
at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:147)
at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:357)
at coldfusion.filter.CfincludeFilter.invoke(CfincludeFilter.java:62)
at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:107)
at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:43)
at coldfusion.filter.PathFilter.invoke(PathFilter.java:80)
at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:47)
at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)
at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:35)
at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:43)
at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
at coldfusion.CfmServlet.service(CfmServlet.java:105)
at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:91)
at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:252)
at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:527)
at jrun.servlet.jrpp.JRunProxyService.invokeRunnable(JRunProxyService.java:192)
at jrunx.scheduler.ThreadPool$DownstreamMetrics.invokeRunnable(ThreadPool.java:348)
at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:451)
at jrunx.scheduler.ThreadPool$UpstreamMetrics.invokeRunnable(ThreadPool.java:294)
at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)
octupii said on Feb 5, 2005 at 8:48 AM :
the problem i described was resolved by my hosts tech support:

I believe that the problem is cased by the short path to the file that you are using, please try to use "D:\FTP\twojakes\Htdocs\....\images\products\thumbs\#image#" and let us know the results. Probably, there is no read access allowed to that folder/file?
Hutz said on Jul 11, 2006 at 1:34 PM :
You know, for examples of these kinds of functions, instead of some convoluted result of a function of a variable for the parameter in the example, it would be *much* more helpful if it would just give a straight forward example with a simple parameter so you can see simple things like "do I need to put the path in quotes or not?"

FileExists(c:\foo\bar.txt) or FileExists("c:\foo\bar.txt") would be MUCH more useful in a reference than the current FileExists(ExpandPath(yourfile))
This is a common problem with the examples.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6.1/htmldocs/functi79.htm