1

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?

willywonka
  • 13
  • 5
  • Welcome to Super User! Please note that https://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 [ask]. – DavidPostill Apr 17 '20 at 11:42

1 Answers1

0

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 '20 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 '20 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 '20 at 12:07
  • Thank you once again everything work fine – willywonka Apr 17 '20 at 12:29
  • problem solved mark this as complete – willywonka Apr 17 '20 at 12:40
  • "The system cannot find the file specified" could happen if you have in **Folder 2** files which are **not** in **Folder 1**. This is the reason why I specified that as an assumption in my answer. – Danilo Schembri Apr 17 '20 at 12:59