1

I'm having a nightmare trying to copy files from multiple directories into a single directory.

Basically I received a data set with individual png files in individual folders. What I want is one folder with all the png files.

The reason I want to do this with code is that the data set has approx. 6000 folders, so it is not practical to do it manually. This can be done with WinApi as I have no need to make this cross platform. I just want to merge the bloody folders.

So far I have managed to get the paths to the png files all saved into a .txt which are saved on each line.

Example:

C:/Users/rudwi/Documents/Visual_Studio_2017/Projects/ExtractPhotos/ExtractPhotos/lfw-deepfunneled/Abbas_Kiarostami/*.png

Just wondering is there a way I can move from the path above to a different dir.

The solution given by ANON I believe was for linux but it is pretty much the same using xCopy from the command line. Instead, just add /s before the source path to include everything in the directory. Hope this helps someone.

Paul Hashmi
  • 456
  • 5
  • 18
  • I have a solution that was written in C#, where it is a recursive function (copy and pastes a whole directory WITH all subfolders in the directory), and it takes a source and a destination path. You should be able to convert it to C++. Hold on – Khalil Khalaf May 10 '17 at 21:15
  • Na I need to remove the subfolders thanks though Kyle – Paul Hashmi May 10 '17 at 21:16
  • if it's c++, you can use SetCurrentDirectory() to set your desired directory. the loop through all the file names (with path name) , load images and save them in current directory .. naive .. but it should work – K.M. Shihab Uddin May 10 '17 at 21:16
  • if you want to delete a folder / subfolder .. follow this one http://stackoverflow.com/questions/734717/how-to-delete-a-folder-in-c – K.M. Shihab Uddin May 10 '17 at 21:17

4 Answers4

2

a script for cmd may look something like that:

set DESTDIR= C:\DestinationPath\
for /f "delims=" %%i in (filelist.txt) do (xcopy "%%i" %DESTDIR% /i /y )

Note, don't forget backslash at end of destination. of course, script can be parameterized:

set DESTDIR= %2
for /f "delims=" %%i in (%1) do (xcopy "%%i" %DESTDIR% /i /y )

put that into a mcopy.cmd file, and it can be used as this:

mcopy filelist.txt C:\DestinationPath\

Swift - Friday Pie
  • 12,777
  • 2
  • 19
  • 42
1

It's easier to just create a .bat file of the commands to do a copy since you already have the source paths.

In your favorite editor do the following:

  1. Prepend 'cp ' to all of your lines.

  2. Append ' destination path' to all of your lines.

  3. Rename the file to .bat and run it from a cmd window.

As an example change your line above from

C:/Users/rudwi/Documents/Visual_Studio_2017/Projects/ExtractPhotos/ExtractPhotos/lfw-deepfunneled/Abbas_Kiarostami/*.png

to

cp C:/Users/rudwi/Documents/Visual_Studio_2017/Projects/ExtractPhotos/ExtractPhotos/lfw-deepfunneled/Abbas_Kiarostami/*.png C:/DestinationPath
Anon Mail
  • 4,660
  • 1
  • 18
  • 21
1

When I had to do something like that and if I needed it done once quickly without writing any scripts I'd do this:

collect all png files from subdirs: dir /s /b *.png > copy.bat

Then modify your copy.bat by adding @echo off at the top and prepend each filename with call:mycopy and then at the bottom of copy.bat add:

goto:eof
:mycopy
copy %1 C:\mynewdir
exit /b 0

Not the best approach, but it's quick to do without really doing any scripting. Then when running that copy.bat I'd check output for errors for duplicate filenames.

Pavel P
  • 15,789
  • 11
  • 79
  • 128
0

If it is Windows I would use Agent Ransack to search for all pngs and cut and copy them from the list to the new folder.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 25 '23 at 18:04