Earlier I had posted my .vbs script for deleting files that were more than ‘x’ days old.
I just ran across this script that accomplishes the same thing, using Windows 2003′s native forfiles comand (scroll down to step 4).
echo on
rem First Delete old SQL Backup Files
FORFILES /p C:\filename /s /m *.* /d -3 /c “CMD /C del /Q @FILE”
rem pause
Save the script with a .bat or .cmd extension and schedule it using the Windows Scheduled Tasks applet.
{ 11 comments… read them below or add one }
Excelent – this what I wanted instead of big scary vbs script
and since I wanted to securely erase files – I just put instead of del – sdelete – nice and clean solution
Thanks for making life easier.
Thank you for this! I’ve been trying to find a good way to remove old SQL backups and this just hit the nail on the head.
Great!
Hey Julie….just wanted to let you know that “fancy quotes” in your code need to be changed before the script works
Also, is there a way to make it report out the files that it is deleting? Mine doesn’t do that. I’m using it at the top of my ntbackup script for my external harddrive….
FORFILES /p F:\ /m *.bkf /d -16 /c “CMD /C del /Q @FILE”
for /f “Tokens=1-4 Delims=/ ” %%i in (‘date /t’) do set dt=%%j%%k%%l-%%i
for /f “Tokens=1″ %%i in (‘time /t’) do set tm=-%%i
set tm=%tm::=%
set dtt=%dt%%tm%
C:\WINDOWS\system32\ntbackup.exe backup systemstate “@C:\Documents and Settings\Administrator\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data\scripts\CD-Copy-S.bks” /n “CD-Copy-S-%dtt%” /d “CD-Copy-S-%dtt%” /v:no /r:no /rs:no /hc:off /m copy /j “CD-Copy-S” /l:s /f “F:\%dtt%.bkf”
forfiles command doesn’t work on windows xp.
pls suggest
Paris
Paris,
Just grab a copy of forfiles.exe from a Windows 2003 server and copy it to your XP workstation.
-Julie
Great script with forfiles command !
And if I need to keep at least 3 files in every directory too ?
big thanks for help
tested on windows 7 and server 2003, thanks.
In the voice of comic book guy:
BEST…
COMMAND…
EVER.
{ 1 trackback }