Creating batch script to keep a set number of items

Tom Waller

Estimable
Jan 14, 2015
20
0
4,570
Hi guys,

I need some help/guidance with a batch script I need to make.
We have 1 location where our Veeam backup, stores the daily backups. This consists of a weeks backup.
We also have a copy of these backups in another location run by a script I created in notepad (which works)

Is there any way a batch script can be created to limit the amount of backup files that enters that copy folder at one time like the previous backup location. We often have to go in and manually remove older backup files which aren't needed once every so often so a batch file would be useful.

Hope this makes sense..
Much appreciated

Thanks In advance
 
Solution
not sure if you want to limit number of files or remove older than n days files.
In either case, you can google a LOT of examples, short and small.
https://stackoverflow.com/questions/51054/batch-file-to-delete-files-older-than-n-days/6149776#6149776
Code:
forfiles /p "v:" /s /m *.* /d -3 /c "cmd /c del @path"
You should do /d -3 (3 days earlier) This works fine for me. So all the complicated batches could be in the trash bin. Also forfiles don't support UNC paths, so make a network connection to a specific drive.

little_me

Estimable
May 9, 2015
151
3
4,910
not sure if you want to limit number of files or remove older than n days files.
In either case, you can google a LOT of examples, short and small.
https://stackoverflow.com/questions/51054/batch-file-to-delete-files-older-than-n-days/6149776#6149776
Code:
forfiles /p "v:" /s /m *.* /d -3 /c "cmd /c del @path"
You should do /d -3 (3 days earlier) This works fine for me. So all the complicated batches could be in the trash bin. Also forfiles don't support UNC paths, so make a network connection to a specific drive.
 
Solution

Tom Waller

Estimable
Jan 14, 2015
20
0
4,570
Ah legend, cheers mate, adjusted it slightly and just ran a test. Works as hoped!