ColdFusion Tip: How to tell if path is file or directory
Join the DZone community and get the full member experience.Join For Free
For a moment I thought really! is there no way that ColdFusion can tell you whether a given path is of a directory or file? But sooner, I came across the function 'getFileInfo' which takes the path as an argument and returns a struct data that contains various metadata properties of the file. The struct includes a key - 'type' whose value can either be a directory or file. The below code shows how you can determine whether the given path is of a directory or file:
<cfset fileInfo = getFileInfo(expandPath("./myDir")) > <cfif fileInfo.type EQ "directory"> <!--- is a directory ---> <cfelseif fileInfo.type EQ "file"> <!--- is a file ---> </cfif> <cfdump var="#fileInfo#">
The other metadata properties such as canRead, canWrite, isHidden, lastModified, parent, size included in the resultant struct can also come handy.
Opinions expressed by DZone contributors are their own.