Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Query a Directory and delete all files more than 1 hour old

Participant ,
May 12, 2009 May 12, 2009

How would I query a directory and delete all files from that directory that are more than 1 hour old?

I have used CFDIRECTORY before to post pages to the directory and to get directory info but I cant figure out how to query a directory and delete all files more than 1 hour old from that directory.

1 hour old means that the time NOW is more than an hour from the file's date/time on the server.

1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Valorous Hero , May 12, 2009 May 12, 2009

You need to user a combonation of the <cfdirectory...> tag to read the files and the <cffile ...> to delete the files in conjuction of a <cfif> tag to decide when and when not to do the deletion.  The dateDiff function would be handy in that decision.

In pseduo code:

<cfdirectory directory="theDir" name="theFiles"...>

<cfloop query="theFiles">

   <cfif dateDiif(theFiles,now(),'h") GT 1>

     <cffile action="delete" file="theFiles.name"...>

  </cfif>

</cfloop>

NOTE:  Pay close attention to how the dateDi

...
Translate
Valorous Hero ,
May 12, 2009 May 12, 2009
LATEST

You need to user a combonation of the <cfdirectory...> tag to read the files and the <cffile ...> to delete the files in conjuction of a <cfif> tag to decide when and when not to do the deletion.  The dateDiff function would be handy in that decision.

In pseduo code:

<cfdirectory directory="theDir" name="theFiles"...>

<cfloop query="theFiles">

   <cfif dateDiif(theFiles,now(),'h") GT 1>

     <cffile action="delete" file="theFiles.name"...>

  </cfif>

</cfloop>

NOTE:  Pay close attention to how the dateDiff works with fractional amounts.  I.E 59 minutes and 59 seconds is 0 hours while 1 hour and 1 second is 1 hour with the 'h' percision value.

Also note that I did NOT look up the syntax for any of these tags and I probably misnamed and|or misorderd the parameters.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources