Apagada docs

Aprendiendo a programar el pasado

Herramientas de usuario

Herramientas del sitio


Delete files of FOLDER1 already on CARPETA2 (and equal)

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.

  1. Substitute FOLDER1 by drive letter X:. FOLDER1 is the folder where files will be DELETED.
    subst X: FOLDER1
  2. Substitute FOLDER2 by drive letter Y:. FOLDER2 is the folder where files will be KEPT.
    subst Y: FOLDER2
  3. Run this to show up the substitued drive letters and then check X: and Y: are not pointing to same folder, and X: is the folder where you want do DELETE files:
  4. It is desirable to check (manually) FOLDER1 is not a link to FOLDER2. This script does not check it.
  5. Wrtie up the following CMD “One liner” (they are really many lines, but CMD will understand it as a single line, asking for more text until you close all parenthesis):
    for /R X:\ %a in (*.*) do (
    echo n|comp "X:~%pnxa" "Y:~%pnxa"
    if errorlevel 1 (
    rem nothing
    ) else (
    del "X:~%pnxa"
  6. After deleting all duplicate lines, repeatedly run this to delete empty folders:
    for /R /D %a in (*.*) do rmdir "%a"
Este sitio web utiliza cookies. Al utilizar el sitio web, usted acepta almacenar cookies en su computadora. También reconoce que ha leído y entendido nuestra Política de privacidad. Si no está de acuerdo abandone el sitio web.Más información
en/bat/delete_files_of_folder1_already_on_folder2.txt · Última modificación: 2022/03/31 05:55 por nepenthes