Reputation: 83
I have two directory on a Network drive . X:\MAPS and X:\MAPS2 Directory 1 and 2 have a bunch of files.
I need a batch file that will: Read each file in Directory 1 and checks, if same file exists in Directory 2 then copy this file to a different Directory X:\MAPS3 Read the next file, and so on.. At the end, I end up have X:\MAPS3 which has only the duplicate files from 1 and 2.
Upvotes: 1
Views: 5320
Reputation: 11367
for %%F in (X:\MAPS\*) do if exist "X:\MAPS2\%%~nxF" copy "%%~fF" "X:\MAPS3\%%~nxF"
Extended Answer for Comment
for %%F in (X:\MAPS\*) do (
if exist "X:\MAPS2\%%~nxF" copy "%%~fF" "X:\MAPS3\%%~nxF"
if exist "X:\MAPS5\%%~nxF" copy "%%~fF" "X:\MAPS3\%%~nxF"
if exist "X:\MAPS7\%%~nxF" copy "%%~fF" "X:\MAPS3\%%~nxF"
if exist "X:\MAPS8\%%~nxF" copy "%%~fF" "X:\MAPS3\%%~nxF"
if exist "X:\MAPS9\%%~nxF" copy "%%~fF" "X:\MAPS3\%%~nxF"
)
Upvotes: 1
Reputation: 9453
In a batch file:
cd /d X:\MAPS
for %%i in (*.*) do if exist "X:\MAPS2\%%1" copy "%%i" X:\MAPS3
From a command prompt:
C:>cd /d X:\MAPS
X:\MAPS>for %i in (*.*) do if exist "X:\MAPS2\%i" copy "%i" X:\MAPS3
Upvotes: 0