Deleting duplicate files with different name

So this thing happened, on one computer after restoration all of the files somehow got duplicated. I am not sure how that happened, but by duplicate I mean there were the same folders but with _2 in the end. Each folder had exactly the same files as in a normal folder. Every good folder had subfoldes that were the also duplicated and named *_2.
Obviously this can’t be cleaned by hand, so here’s a script I made to clean such a mess. It can be applied to any pattern, just change to match your situation in dir /b /s /a:d “*_2”

@echo off
echo.
for /f "tokens=*" %%P in ('dir /b /s /a:d "*_2"') do call :loop "%%P"
:loop
if '%1' == '' goto :endloop
rd /S /Q %1
echo %1 was deleted.
:endloop
Subscribe
Notify of
guest

2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments