1

I have many files in folder1 and I would like to move them to folder2. There are a small number of files already in folder2 (a hundred compared to several thousand in folder1) and I would like to move all files from folder1 to folder2 except when there is a file name conflict. (At that point I'll examine the remaining files individually and skip/modify/replace as needed.)

Is there a good way to do this? I'm on Windows 10 but I can use bash via MinGW if it's more convenient.

This is like Batch File Copy and Move without overwriting except that it involves thousands of files instead of a single file.

3
  • @Ƭᴇcʜιᴇ007 The accepted answer moves only a single file, which is very different from my use case. (I wouldn't mind being closed as a duplicate but that doesn't seem like a duplicate to me.)
    – Charles
    Aug 24, 2016 at 14:49
  • From the accepted answer: "Interestingly, it seems to work with wildcards as well." which it should. :) Aug 24, 2016 at 14:50
  • I don’t understand the issue with the issue. x) Explorer should move and prompt you when it arrives at a file that exists at the target location. You would then choose not to move it and also apply that action to all queries of the same kind.
    – Daniel B
    Aug 24, 2016 at 14:54

1 Answer 1

1

I want to move all files from folder1 to folder2 unless there is a file name conflict.

Use the following batch file (located in the parent directory of folder1 and folder2.

MovesFiles.cmd:

@echo off 
setlocal enabledelayedexpansion
for /f %%f in ('dir /b folder1') do (
  if not exist folder2\%%~nxf move folder1\%%~nxf folder2 
  )
endlocal

Notes:

  • Any files where there is a name conflict (ie already exist in folder2) are left in folder1.
  • All other files are moved.

Example usage:

F:\test>dir /b folder1
1.txt
2.txt
3.txt
4.txt
5.txt

F:\test>dir /b folder2
2.txt
4.txt

F:\test>MoveFiles.cmd
        1 file(s) moved.
        1 file(s) moved.
        1 file(s) moved.

F:\test>dir /b folder1
2.txt
4.txt

F:\test>dir /b folder2
1.txt
2.txt
3.txt
4.txt
5.txt

Further Reading

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