tags:

views:

143

answers:

3

I have a requirement, which says,

If file exists and is not readable then Update in DB with 
 file path and some Status.

Is it possible to Have File Exists and is not readable?

Is Yes, How to identify through coldfusion such type of files, I know we can identify if it is exists or not, but i wanted to know, how to identify If it is readable or no?

I am using Windows server and Coldfusion 8

Thanks,

+3  A: 

It's possible a file exists but you do not have the right permissions to read it.

I found this:

GetFileInfo(filepath) - So far till ColdFusion 7, there was no good way to find information like size, last modified date etc about a file. Only way you could do that was to use cfdirectory tag to list the directory, get the query from it, loop over the query until you hit the desired file and then fetch the required metadata. The new function GetFileInfo in ColdFusion 8 provides an easy way to get all the meta-data about a file or directory. This returns a struct which is described below.

  • name - Name of the file/directory specified. This is just the file name and not the absolute path.
  • path - Full path of the file/directory.
  • parent - Full path of the parent directory.
  • type - "directory" if the filepath is a directory else "file".
  • size - size of the file in bytes.
  • lastmodified - DateTime at which this file/directory was last modified.
  • canRead - "true" if this file/directory has 'read' permission. "false" Otherwise.
  • canWrite - "true" if this file/directory has 'write' permission. "false" Otherwise.
  • isHidden - "true" if this file/directory is hidden. "false" Otherwise.
nickd
With MX7 you could always use a bit of java code to do return the same information (and more). But I agree there was no easy/built-in way to achieve this.
Leigh
+1  A: 

This probably means that the file is opened for writing, or that the current user doesn't have read access to it.

Tor Valamo
+4  A: 

By using GetFileInfo(path) you can get the size of the file and whether or not read and write permissions are enabled. It will also return the 'type', but it's simply 'file' vs 'folder', not mime-type.

Example:

<cfset test = GetFileInfo(myFilePath)>
<cfdump var="#test#">

Example in use:

<!--- Check if file exists and is not readable --->
<cfif fileExists(myFilePath) AND NOT GetFileInfo(myFilePath).canRead>
    <!--- then Update in DB with file path and some Status --->
</cfif>

If your requirement assumes that you're validating the file type and not just the ability to open the file, then you will need to update your question to list the file types you must test for so that we can help you out with that part. Some types can be validated by Coldfusion, others may require some Java.

Dan Sorensen
Dan, This is what I am looking for, Thanks you
CFUser