Computing.Net > Forums > Disk Operating System > Finding duplicate files in 2 dirs

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Finding duplicate files in 2 dirs

Reply to Message Icon

Name: aml
Date: October 31, 2002 at 11:54:50 Pacific
OS: Win98 & WinNT
CPU/Ram: n/a
Comment:

This forum has been extremely helpful to me and I wanted to share this batch file.
It was created by Leonardo (aka Secret_Doom) and I want to thank him immensely for his help.

As noted in his file, this batch file will work with both Win98 and WinNT. It compares the files in DIR1 to DIR2. If duplicates are found, it removes the duplicate from each and places it in DIR3.


:: -----
:: Author: Leonardo Pignataro (secret_doom@hotmail.com)
::
:: Compare filenames from %DIR1% and %DIR2%, place a copy
:: of the matches on %DIR3% and delete originals.
::
:: Designed and tested under:
:: Windows 98 Second Edition and Windows XP Professional
:: -----
@echo off
if "%1"=="GoTo" GOTO %2
%comspec% /E:2048 /C %0 GoTo start
goto eof
:start

:: Set directories below. Use short names (e.g.: c:\progra~1)
set DIR1=C:\DIR1
set DIR2=C:\DIR2
set DIR3=C:\DIR3

if "%OS%"=="Windows_NT" goto NT

XCOPY /I/L/N/U/Y %DIR1%.\*.* %DIR2% |FIND/v " " > %temp%.\T1.BAT
echo e100'SET %%1='> %temp%\T3.DAT
for %%? in (rcx 7 w q) do echo %%?>> %temp%.\T3.DAT
type nul> %temp%.\T2.DAT
DEBUG %temp%.\T2.DAT nul

:loop
copy %temp%.\T1.BAT nul > %temp%.\T3.DAT
FIND " 0 " nul
if not errorlevel=1 goto loopend
copy/y %temp%.\T2.DAT+%temp%.\T1.BAT %temp%.\T3.DAT > nul
FIND "SET %%1=" %temp%.\T1.BAT
call %temp%.\T1.BAT FILE
echo Duplicate found - %FILE%
copy %DIR1%.\%FILE% %DIR3% > nul
for %%? in (%DIR1% %DIR2%) do del %%?.\%FILE%
FIND/V "SET %%1=" %temp%.\T1.BAT
goto loop

:loopend
for %%? in (T1.BAT T2.DAT T3.DAT) do del %temp%.\%%?
goto eof

:NT
for %%? in (%DIR1%\*.*) do (
if exist %DIR2%\%%~nx? (
echo Duplicate found - %%~nx?
copy %%? %DIR3% > nul
del %%?
del %DIR2%\%%~nx?
)
)

:eof
------------------------


Thanks!
-aml



Sponsored Link
Ads by Google

Response Number 1
Name: Secret_Doom
Date: October 31, 2002 at 17:38:30 Pacific
Reply:

Thanks for the credit. However, the script was modifyed because of post problems (besides, some lines wrapped). Below is the full working script (the script you posted won't do what it should).

===== BATCH SCRIPT BEGIN =====
:: -----
:: Author: Leonardo Pignataro (secret_doom@hotmail.com)
::
:: Compare filenames from %DIR1% and %DIR2%, place a copy
:: of the matches on %DIR3% and delete originals.
::
:: Designed and tested under:
:: Windows 98 Second Edition and Windows XP Professional
:: -----
@echo off
if "%1"=="GoTo" GOTO %2
%comspec% /E:2048 /C %0 GoTo start
goto eof
:start

:: Set directories below. Use short names (e.g.: c:\progra~1)
set DIR1=C:\DIR1
set DIR2=C:\DIR2
set DIR3=C:\DIR3

if "%OS%"=="Windows_NT" goto NT

XCOPY /I/L/N/U/Y %DIR1%.\*.* %DIR2% |FIND/v " " > %temp%.\T1.BAT
echo e100'SET %%1='> %temp%\T3.DAT
for %%? in (rcx 7 w q) do echo %%?>> %temp%.\T3.DAT
type nul> %temp%.\T2.DAT
DEBUG %temp%.\T2.DAT < %temp%.\T3.DAT > nul

:loop
copy %temp%.\T1.BAT nul > %temp%.\T3.DAT
FIND " 0 " < %temp%.\T3.DAT > nul
if not errorlevel=1 goto loopend
copy/y %temp%.\T2.DAT+%temp%.\T1.BAT %temp%.\T3.DAT > nul
FIND "SET %%1=" < %temp%.\T3.DAT > %temp%.\T1.BAT
call %temp%.\T1.BAT FILE
echo Duplicate found - %FILE%
copy %DIR1%.\%FILE% %DIR3% > nul
for %%? in (%DIR1% %DIR2%) do del %%?.\%FILE%
FIND/V "SET %%1=" < %temp%.\T3.DAT > %temp%.\T1.BAT
goto loop

:loopend
for %%? in (T1.BAT T2.DAT T3.DAT) do del %temp%.\%%?
goto eof

:NT
for %%? in (%DIR1%\*.*) do (
    if exist %DIR2%\%%~nx? (
        echo Duplicate found - %%~nx?
        copy %%? %DIR3% > nul
        del %%?
        del %DIR2%\%%~nx?
    )
)

:eof
===== BATCH SCRIPT END =====

-- Leonardo Pignataro - Secret_Doom --

secret_doom@hotmail.com
www.batch.hpg.com.br

__________________________________________________________________


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Finding duplicate files in 2 dirs

Batch for processing all files in a Dir. www.computing.net/answers/dos/batch-for-processing-all-files-in-a-dir/10802.html

Script for removing files(2 dirs) www.computing.net/answers/dos/script-for-removing-files2-dirs/10734.html

How to find & delete files in DOS www.computing.net/answers/dos/how-to-find-amp-delete-files-in-dos/5401.html