[windows] Copy files older than X days



These days I tried to create a script that will copy the files older than 40 days from a backup folder to another location. I found a handy method which allows the copying of old files from a directory, usingXXCOPY. This tool provides a logical extension to XCOPY and adds many innovative features.

Below is a small batch script that does the job:

@echo on

set olderthan=40
set source=C:\work\BT
set destination=C:\work\copy

:: /E  Copies directories and subdirectories, including empty ones
:: /Po0  Suppresses warning on file-overwrite (Legacy /Y)
:: /DB#  Copies files that were changed on or before  days ago.
xxcopy %source% %destination% /E /Po0 /DB#%olderthan%