Move media files, big files and all files older than seven days
Task
Clean up all users home directories. Remove all media files, files bigger than 5M and files older than seven days. Create a backup copy of all removed files just in case.
SET RootDir=e:\users
SET CopyTo=w:\tempremove
SET CopyFilesOlderThan=7
[Settings_End]
[Init_Batch_Begin]
// Fill [Data] section with details for all files
Data.Get.FileList %RootDir%, Path§1§SubPath§2§Accessed§3§Extension§4§Size§5§
Data.Loop
// Move all media files -> keep details in [Data] section
ifMultiCompare (%col4%,.mpg§.avi§.wav§.mp3§)=1 Then Data.Write 8,Media
Data.NextLoop EndIf
// Move all files where size > 5M -> keep details in [Data] section
if %col5% > 5000000 Then Data.Write 8,Size
Data.NextLoop EndIf
// Move all files older than seven days -> remove [Data] rows with details for newer files
If %Date% < DateAdd(copy(%col3%,1,10),%CopyFilesOlderThan%) Then Data.Row.Delete Else Data.Write 8,Age
EndIf Data.EndLoop Data.Show
[Init_Batch_End]
[Batch_Begin]
Data.Loop
// Pipe f to answer question "Does _filename_ specify a file name or directory name on the target", may need to change when using non-English OS
// V = verify, H = copies hidden & system files also
DOS echo f| xcopy "%col1%" "%CopyTo%\%col2%" /V /H
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, sub path (used by xcopy), last access time, extension and size for all files in the directory specified by RootDir variable (and subdirectories). Then file type, size and last access time are checked - details for files that should not be moved are deleted from the [Data] section. A status indicator is also written in column 8 for you to see why the script wants to move a certain file. The "Data.Show" command displays a window with all remaining files, where you can choose to continue and move 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 process the wrong files.