Just a quick note.

I do just this sort of thing to deal with temporary files.  It is scheduled
to run every two hours.

One problem that we came across is if the file is being used.  We ended up
adding a cftry..cfcatch setup to ensure that if one file was being used, the
cf page would continue with the rest of the files.  Without this combo, the
page would crash at the first file it couldn't delete.  This can be a major
problem if IIS has locked a file.

just my .02

Steve Durette

----- Original Message -----
From: "David Adams" <[EMAIL PROTECTED]>
To: "CF-Talk" <[EMAIL PROTECTED]>
Sent: Tuesday, December 03, 2002 5:15 PM
Subject: Code Summary: Recursive File Delete


> For the benefit of others the following is a summary of the code
> snippets sent in from the various developers.  Thanks to all that
> responded.
>
> Dave Adams
> CFUG Ottawa
>
>
> <cfexecute
>       name="c:\winnt\system32\cmd.exe"
>       parameters="/c del c:\trash\*.* /q" />
>
> OR
>
> <cfset mypath = expandpath("my/directory/path") />
> <cfdirectory action="list" name="rsfile" directory="#mypath#" /> <cfloop
> query="rsfile">
>       <cfif rsfile.type is "file">
>             <cffile action="delete" file="#mypath#/#rsfile.name#" />
>       </cfif>
> </cfloop>
>
>
> OR
>
> <cfset root="c:\inetpub\wwwroot\yourdirectory\">
> <cfdirectory name="dGetDir" directory="#root#" action="List"> <cfloop
> query="dGetDir">
>       <cfif type NEQ "DIR">
>             <cffile action="DELETE" file="#root##dGetDir.name#"
> variable="content">
>       </cffile>
> </cfloop>
>
> OR
>
> <CFSET TargetDir = "c:\foo">
> <CFDIRECTORY ACTION="LIST" DIRECTORY="#TargetDir#" NAME="TheFiles">
> <CFLOOP QUERY="TheFiles">
>       <CFIF (Type IS "File") AND (Name IS NOT ".") AND (Name IS NOT
> "..")>
>             <CFFILE ACTION="DELETE" FILE="#TargetDir#\#Name#">
>       </CFIF>
> </CFLOOP>
>
>
> OR
>
>
> < cfdirectory action="list" directory="mydirectory" name="dirlist">
> < cfoutput query="dirlist">
>       < cffile action="delete" file="#name#">
> < /cfoutput>
>
>
>
>
> 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription: 
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Signup for the Fusion Authority news alert and keep up with the latest news in 
ColdFusion and related topics. http://www.fusionauthority.com/signup.cfm

Reply via email to