Find files that are older than given date

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

Find files that are older than given date

Post by Petr » Wed Nov 23, 2016 4:31 pm

This macro shows how to find in given folder all files that are older than given date.

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\","")

<#> Define file types (mask)
<varset>("vMask=*.*","")

<#> Get list of files matching the mask
<file_enum>("%vFolder%\%vMask%",2,vFiles,vFilesNum)

<#> Loop on all files
<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