1

I have two directory on my D drive. D:\1 and D:\2. Directory 1 and 2 and subdirectories have a bunch of files.

I need a batch file that will:

  • Read each file in Directory 1 and check if the same file exists in Directory 2
  • Avoids duplicates files
  • Moves only those files which are not present in directory 2 to a different directory C:\3 with the same folder structure.
  • Read the next file, and so on.

At the end I have C:\3 which has only the unique files from 1. I know I can drag and drop … but I need this in a batch file.

2 Answers 2

1
robocopy "D:\dira" "D:\dirb" /MIR /XO /W:5 /V /LOG:"D:\dira\log.txt"
exit

save as foo.cmd and run it when you want, or schedule it in task manager

source

  • /mir: Mirrors a directory tree
  • /xo: Excludes older files.
  • /w:5: Specifies the wait time between retries, in seconds
  • /v: Produces verbose output, and shows all skipped files.
  • /log: Writes the status output to the log file (overwrites the existing log file).
14
  • If you use /W:5 you should also use /R:x (default retry value is 1.000.000). /MT:x is a second suggest i would made.
    – nixda
    Jul 16, 2013 at 14:47
  • @nixda good catch Jul 16, 2013 at 14:48
  • can script be edited rather than giving output to log.txt file, Missing file should directly copy to backup folder? Jul 17, 2013 at 4:51
  • @KalimSayyed The log file just tells you what changes occurred and if there were no errors. It can write the log file to anywhere. Jul 17, 2013 at 8:32
  • The issue is i have made a batch script to copy day older files from dir and subdir on basis of modified date and store into backup folder with same dir structure of root... Now many of the files are missing (not copied from source folder). Now i am requiring batch script to search for missing file which not copied... Jul 18, 2013 at 4:34
0
@echo off
set "d1=D:\Login1"
set "d2=D:\Login2"
set "d3=D:\RESULT"

for /R "%d1%" %%F in ("*") do (
    if not exist "%d2%\%%~nxF" move "%%~fF" "%d3%"
)

As proposed by Kalim at https://superuser.com/questions/624007/by-searching-dir1-and-dir2-and-move-unique-file-from-dir1-to-dir3

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .