Wednesday 23 August 2017

command line - Delete duplicate files with Windows batch file


I have a program that automatically copies files to a directory, and if it creates a duplicate it will name it like so:


file with duplicate.xxx
file with duplicate - 1.xxx
file with duplicate - 2.xxx

I need a way to delete all the duplicates with a Windows batch file.


Something along the lines of:


FOR %f IN (C:\files\*.*) DO del "%f - 1"

However, that will not work because that would resolve to file with duplicate - 1.xxx - 1



Answer



If you want to delete all the files with a name that ends in - ?, then you were close.


Try this:


FOR %%f IN ("C:\files\* - ?.*") DO del "%%f"

You will need to double up the percent signs if you are running it from a batch file. And test with an echo instead of a del first.


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...