Example: Folder 1 has A to Z file name Folder 2 has only V to Z file name

I want to move then replace file in Folder 2 only with same name from file in Folder 1. is there a cmd/script...etc to do this?

  • Welcome to Super User! Please note that superuser.com is not a free script/code writing service. If you tell us what you have tried so far (include the scripts/code you are already using) and where you are stuck then we can try to help with specific problems. You should also read How to Ask.
    – DavidPostill
    Apr 17, 2020 at 11:42

1 Answer 1


We suppose you have only two folders (Folder 1 and Folder 2).

In Folder 2, you have file names which are surely also in Folder 1.

You want to move (overwrite) from Folder 1 to Folder 2 only files with the same name; as a result in Folder 2, you will have the same number of files, while in Folder 1 you will have fewer files because they had to be moved.

In CygWin you can do:

find Folder2 -maxdepth 1 -type f -printf %f\\n | while IFS= read -r filename ; do mv "Folder1/$filename" "Folder2" ; done

For cmd you can do:

for /f "delims=" %f in ('dir /b "Folder2"') do move /y "Folder1\%f" "Folder2"
  • thank you, will this only move and replace file with same name only from Folder 1 to Folder 2 or it will move and replace than add unmatch file name from folder 1 to folder 2>
    – willywonka
    Apr 17, 2020 at 11:04
  • i will try your cmd script, i will post later, take time im new to this kind of thing,
    – willywonka
    Apr 17, 2020 at 11:13
  • Test with cmd with some random file, work like charm!!!, can you make it clear "The system cannot find the file specified" log cmd output msg, cus in folder 1 i had 13,795 file 5.04 GB while in Folder 2 3,539 Files 1.12 GB i dont start run it yet worry cmd frezze or something happen
    – willywonka
    Apr 17, 2020 at 12:07
  • Thank you once again everything work fine
    – willywonka
    Apr 17, 2020 at 12:29
  • problem solved mark this as complete
    – willywonka
    Apr 17, 2020 at 12:40

You must log in to answer this question.

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