Wednesday, June 15, 2011

Deleting Files from Windows

Delete files more than X days old in Windows "forfiles" is part of the resource kit, but ships with Windows 2003 Server and later.

forfiles -p d:\mssql_backup -s -m *.bak -d -2 -c "cmd /C del @Path"

1. -p: Start in the directory d:\mssql_backup
2. -s: process subdirectories
3. -m: match files using *.bak
4. -d: Find files more than 2 days old
5. -c: Execute the del command to delete the file. @Path has double-quotes around it already.

1 comment: