How to delete files older than given date

Share your macros, knowledge, solutions, services, ...
Post Reply
Petr
Posts: 106
Joined: Tue Oct 18, 2016 1:12 pm

How to delete files older than given date

Post by Petr » Wed Nov 02, 2016 6:45 am

Macro text:

Code: Select all

<#> Start of the macro
<#> This macro enumerates files from defined folder that are older than defined date
<cmds>
<#> Define date. It MUST be in format YYYY.MM.DD HH:MM.SS
<varset>("vNoOlderThan=2015.5.30 00:00:00","")
 
<#> Define folder
<varset>("vFolder=c:\temp\test","")
 
<#> Define file types (mask)
<varset>("vMask=*.*","")
 
<#> Get list of files matching the mask
<file_enum>("%vFolder%\%vMask%",2,vFiles,vFilesNum)
 
<#> Check last write time for each file in the loop
<for>("f=0","%f% < %vFilesNum%","1")
   <#> Get the file last write time
   <fileinfo>("%vFolder%\%vFiles[f]%","TIME_WRITE_FORCALC","vLastWriteTime")
   <if>("%vLastWriteTime% < %vNoOlderThan%")
      <#> File is matching criteria. Do what you need (delete, archive, etc.)
      <msg>(-100,-100,"File %vFiles[f]% is older than %vNoOlderThan%.","Message",1,0,0,1)
   <endif>
 
<for_end>
<#> End of the macro

Post Reply