Monday, May 4, 2009

Coldfusion File Deletion

Use the following code to delete a particular file using coldfusion language

<cffile action="delete" file="C:\docs\filename.txt">

Coldfusion Directory Listing

Use the following code snippet to list all files from a particular directory,

<cfdirectory action="LIST" directory="#ExpandPath('docs')#" name="dirlist">
<cfloop query="dirlist">
#dirlist.name#
(#NumberFormat(outSize)# kB,
#lsdateformat(dirlist.dateLastModified, 'dddd d mmmm yyyy')#)
</cfloop>

Here "ExpandPath()' returns a absolute URL of the directory.

Use "dirlist.size" to get the filesize.