Delete files older than seven days
Top  Previous  Next


[Settings_Begin]
BatchSettings.Delimiter=;
BatchSettings.MarkerCol=11

SET RootDir=w:\root
SET DeleteFilesOlderThan=7
[Settings_End]

[Init_Batch_Begin]
Data.Get.FileList %RootDir%,Path§1§Accessed§2§   
Data.Loop   
 If %Date% < DateAdd(copy(%col2%,1,10),%DeleteFilesOlderThan%) Then   
  Data.Row.Delete
 EndIf   
Data.EndLoop   
Data.Show   
[Init_Batch_End]

[Batch_Begin]
Data.Loop
 DOS del "%col1%"
Data.EndLoop
[Batch_End]

[Data_Begin]
[Data_End]

About the script

The "Data.Get.FileList" command fills the [Data] section with path and last access time for all files in the directory specified by RootDir variable (and subdirectories). Then last access times are compared to today's date - if a file has been accessed during the last seven days its details is deleted from the [Data] section. The "Data.Show" command displays a window with all remaining files (the ones to be deleted), where you can choose to continue and delete the files or stop the script.

Warning

Remember to backup the source hard drive and to debug the script carefully before doing any real work. You do not want to delete the wrong files.