Here's the setup: I use Macrium Reflect to make daily images of my system drive, which I save in a backup folder in two different backup locations. My problem is that the folder where I save these images gets huge really fast, and I want to limit the number of saved images to, say, 4 or 7. I currently use Belvedere to delete files *older than* – but that can be a problem if, for instance, I travel and spend one month without using the PC (and so without creating new automatic backup images). When I come back and turn on the PC all images will be deleted because *older than*, and I will be left without any backup image.

What I'm looking for is an app or code that may limit the number of files in my backup folder. Something like "if there is more than 'n' files in this folder, delete the oldest file and keep the 'n' newest ones". I'm sure there's more than an easy way to do this, but I can't code and my searches led me to nothing.

I saved the code below as a .bat file, which must then be run as administrator. The number after "skip" is the number of files you want to keep. Older files in the folder that exceed that number will be deleted.