Monday, December 26, 2011

Windows batch file that creates and then utilizes folders based on days date

Where y:\ is target drive
This batch file creates a folder based on the day month and year in MMDDYY format, then copies the files into it. Below I've pasted one we use for a small office backup.

How to delete folders and contents older than n days?


:::begin backup .bat:::

cd "y:\"
for /F "tokens=2-4 delims=/- " %%A in ('date/T') do set var=%%A%%B%%C
md y:\%var%
xcopy "D:\data" "Y:\%var%\data" /E /Y /I /C
xcopy "D:\fax" "Y:\%var%\fax" /E /Y /I /C
...


/d switch makes only backup files that have changed
note, backups can increase inproportionality,  in size especially when you change directory structure

No comments:

Post a Comment