So in the work of doing backups, I need a batch script that would allow me to delete files in a specified directory, that are older than lets say, 3 days. This script will be set as a scheduled task to run at a specified time every day.
feedback
|
|
If powershell is acceptable (should be, as its enabled by default on Server 2008+) try this:
Souce here. | |||||
feedback
|
forfiles -p c:\pathtofiles\ -m *.rar -d -5 -c "cmd /c del @path" Where | |||
feedback
|
|
I like to use DelEn.exe for this. Delen - DELete ENhanced - is a souped-up version of DEL. It supports extended wildcards and parent directories, as well as date, time and size filters. Files can be excluded from deletion. | |||
|
feedback
|
|
You might look at Horst Schaeffer's DelAge32: http://home.mnet-online.de/horst.muc/wbat32.htm#top
Your command can be as simple as:
I have this command running as a scheduled task. | |||
|
feedback
|
|
If you insist on using batch files, Robocopy.exe is your answer. Its fast (multithreaded) and very robust. For your scenario you can use the following as a guide :
There is a long list of options, please do robocopy /? to see them all. You can even use it to do incremental backups, scheduling, creating backup profiles, etc. | |||
feedback
|
|
This is a powershell script I wrote to do what you want - it does a bit more too. I use it to clear down logs and other temporary files. purge-dem-logs.cmd
purgelogs.ps1:
| |||
|
feedback
|
|
This will not work for remote computers. Admins need to manage multiple computers. Below is the script that can be used to delete folders in multiple remote computers without having to login to them. Below script will delete folders older than 15 days. you can change the $days parameter though. D$\Program Files (x86)\Research In Motion\BlackBerry Enterprise Server\Logs is the UNC path for Blackberry Log folder. You can change the directory where your logs/folders are located. List all your server names in servers.txt file and it should located in the same directory as this script.
Save the script as .ps1 and run it. You can schedule it via batch file. That way you need to add Change Directory command at the beginning of the script. Have fun. | ||||
|
feedback
|