Script to delete files on a Windows 7 or 2008 box

So recently I found myself needing to do some log management of some custom logs I was writing to disk. Put this guy in a .bat file and use task manager to keep things in check:

forfiles -p “c:\logs\nginx” -s  -m *.* -d  -1 /C “cmd /c del @PATH”

Two important things to watch out for. After the path CAN NOT include a backslash ‘\’ That will stop it from running. Second, after the -d is the number of days old that you want it to delete. 

Maybe next I’ll create a script to zip the logs and ship them off somewhere.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s