Merging all files into one folder from different folders

command linefile-transfer

I want my files to be copied in one folder, the files came from different folder but in the same location.

I run this code in CMD but it copies the folder into new directory.

xcopy "D:\NBS Contents\Latest Images\*.jpg" "D:\output" /s

The latest images folder has many folders containing images files. I want to combine them into one folder.

Best Answer

So in cmd you'll to have to do the below steps

D:
mkdir output
cd "D:\NBS Contents\Latest Images\"
for /r %f in ( "*.jpg" ) do copy /y "%f" "D:\output"

Step by step explaination:

  • D: - switches to D: drive
  • mkdir output - Creates output directory
  • cd "D:\NBS Contents\Latest Images\" - Changes current directory to the one in quotes

  • for /r %f in ( "*.jpg" ) do copy /y "%f" "D:\output" - Recursively, for every jpg file, copy the source file to d:\output. The /y switch suppresses Are you sure you want to overwrite prompt, you can remove the switch if you want the prompt.

Related Question