Smit Shah

Recursive directory files delete by age

I have a server that has hundreds of thousands of files that have been created over the years. I was trying to do some house cleaning  and ran into this issue where I didnt know how to do a bulk delete without either writing a script or using the interface.
After spending some time trying to find a simple way to do this, I started looking on Google.com for ideas. It wasnt long till I made up my mind to use a MS-DOS script to delete files older than a certain age from all my older directories and sub directories.
 
Finally, the script that worked for me based on results from Google was
forfiles -p "C:\what\ever" -s -m *.* -d <number of days> -c "cmd /c del @path"
 
I found it on this post/page
http://stackoverflow.com/questions/51054/batch-file-to-delete-files-older-than-n-days
 
Hope it saves you time.



EDIT:
I found that the script was not reliable enough, I found a better way of doing it as outlined under
This will delete files from <SOME FOLDER> that are more than 120 days old
forfiles /p "<SOME FOLDER>" /s /m "*.jpg" /c "cmd /c del @path " /d -120

http://technet.microsoft.com/en-us/library/cc753551(v=ws.10).aspx

 

                                                                                         
This is a personal weblog. The opinions expressed here represent my own and not those of my employer. For accuracy and official reference refer to MSDN/ TechNet/ BOL /Other sites that are authorities in their field. Me or employer do not endorse any tools, applications, books, or concepts mentioned on the site. I have documented my personal experience on this site. The information on this site may not be up to date or accurate at times, if you are not sure or have a question, please contact me to verify information.