More About Deleting Files by Age

The resource kit’s Forfiles tool gives you an easy way to delete files by age.

Readers

July 8, 2003

1 Min Read
ITPro Today logo in a gray background | ITPro Today

[Editor's Note: Share your scripting discoveries, comments, problems, solutions, and experiences with products. Email your contributions (500 words or less) to [email protected]. We edit submissions for style, grammar, and length. If we print your submission, you'll get $100.]

I read Moussa Faty's Reader to Reader: "Delete Files by Age" (March 2003, http://www.winscriptingsolutions.com, InstantDoc ID 37718), and I know of an easier way to delete files by age. The Microsoft Windows 2000 Server Resource Kit's Forfiles tool performs a command on each file in a list. For example, if you want to purge all the files in a directory that are older than 10 days, you can go to a command prompt and enter

forfiles -pC:logfiles -m*.* -d-10 -s -c"cmd /c del @FILE"

The -p option is the directory in which to search for files, the -m option selects the files that match the specified string, the -d option specifies the date or days, the -s option recurses subdirectories, and the -c option is the command you want to run.

—David Matuszewski
[email protected]

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like