开发者

Is it Possible to have File Exists and is not readable?

I have a requirem开发者_StackOverflow中文版ent, 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,


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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜