Imagine the following situation: you used Robocopy to update a full system backup, but you forgot you already renamed FOLDER1 to FOLDER2, so your backup now contains FOLDER1 and FOLDER2, both containing the same files.
We will see a solution that is a CMD “one-liner”.
This solution needs CMD.exe (command-line of windows XP and later) and will not work with COMMAND.COM (command line of MS-DOS, windows 95 and so on), since it needs the extended FOR variables Windows XP added.
This solution is designed to write up directly on console by someone that knows what he/she/it is doing.
Substitute % with %% if you are copying this code into a batch file.
subst X: FOLDER1
subst Y: FOLDER2
subst
for /R X:\ %a in (*.*) do ( echo n|comp "X:~%pnxa" "Y:~%pnxa" if errorlevel 1 ( rem nothing ) else ( del "X:~%pnxa" ) )
for /R /D %a in (*.*) do rmdir "%a"