MS DOS script to rename, append date, delete files older than 30 or N days

If you use Windows Server 2003 built-in NTBackup, you may need to move daily backup files into an archive folder, and delete old files.  Here is a script to rename and append time/date to backup file, move it to an archive directory, and search and delete all files older than 30 days.

ren E:\ntbackup\backup2.bkf backup1_%date:~4,2%%date:~7,2%%date:~10,4%_.bkf
move E:\ntbackup\backup?_* E:\ntbackup\archive
forfiles /P “E:\ntbackup\archive” /S /M *.bkf /D -30 /C “cmd /c del @PATH”

Set this as a scheduled task after your NTBackup job completes, and you should be good to go with basic full backup.

 

3 Comments

  1. ren E:\ntbackup\backup2.bkf backup1_%date:~4,2%%date:~7,2%%date:~10,4%_.bkf

    whats meaning of 4,2 7,2 10,4

  2. There is any other way other than using Forfile command…??

  3. I believe the forfile is proper syntax to accomplish this task. There may be other ways to do it, but forfile parses through each one.

Leave a Reply

Your email address will not be published. Required fields are marked *