Link to home
Create AccountLog in
Avatar of Mario Zio
Mario ZioFlag for Italy

asked on

A Batch script to copy files contained in a lot of folders into one big only folder.

Hello,

I'm trying to build a cartoon. I have taken a movie as base and I have exported it in more JPG images (from 1 to 168130). After it,I have splitted the movie into more scenes and I have copied all the images related to them into folders named with the numbers of the images with which they are built. For example the first scene of the movie start from 0 and it ends with the picture n. 4759,I have created a folder named 0-4759 and I have copied there all the images of the first scene,the second scene starts with the pic n. 4760 and it ends with the 5806,I have created a folder named 4760-5806 and I have copied all the images of the scene n. 2 into this folder and so on. Now I would like to build a batch script able to copy all the images contained inside these folders into one big folder only. Thanks.
Avatar of Dale Harris
Dale Harris
Flag of United States of America image

You can do this with Powershell easily:

$files = get-childitem "C:\Test" -recurse
foreach ($file in $files){
copy-item $file.fullname "C:\Test1"
}


Your output will be all of the directories and their contents into one folder.

If you want to exclude folders/directories, then do the following:

$files = get-childitem "C:\Test" -recurse
foreach ($file in $files){
if (!($file.psiscontainer)){copy-item $file.fullname "C:\Test1"}

HTH,

Dale Harris
SOLUTION
Avatar of Rob Hutchinson
Rob Hutchinson
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
ASKER CERTIFIED SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
If you want to script it, then Dale's solution is probably better.
You could do it this way with a Batch/CMD file. Replace the x:\newdir with the drive and folder you want for the destination and x:\source for the source base folder.
Avatar of Mario Zio

ASKER

Assuming that all the folders are located inside "E:\downloads\films\vecchi\Blade Runner\Scene" and I want to copy all the JPG image files into the folder "E:\Temp",I've created this script :

@echo off
for /R "E:\Downloads\Films\Vecchi\Blade Runner\Scene" %D in (.) do copy "%~D\*" "E:\Temp\"

this is the result :

E:\Downloads\Films\Vecchi\Blade Runner>dir

23/12/2010  17:27    <DIR>          Scene
24/12/2010  01:25               114 script.bat
              13 File      1.052.406 byte
               4 Directory   6.425.415.680 byte disponibili

E:\Downloads\Films\Vecchi\Blade Runner>script

~D\*" "E:\Temp\" not expected.
My code didn't attach for some reason:
dir x:\source /s /b > %temp%\filenames.txt
md x:\newdir
REM set delims to something known not to be in the file names in case there is a space in the path
for /f "delims=*" %%x in (%temp%\filenames.txt) do copy %%x x:\newdir

Open in new window

SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
To be more clear,I have attached two screeenshots to show where the JPG image files are...

24-12-2010-01-36-53.jpg
24-12-2010-01-37-29.jpg
24/12/2010  01:36    <DIR>          Scene
24/12/2010  01:42               383 script.bat
              13 File      1.052.675 byte
               4 Directory   6.425.415.680 byte disponibili

E:\Downloads\Films\Vecchi\Blade Runner>script
La seguente sintassi dell'operatore di percorso utilizzata nella sostituzione
del parametro batch non è valida: %~D\*" "E:\Temp\"
Digitare CALL /? o FOR /? per visualizzare i formati validi.
Ok,this code :

@echo off
for /R "E:\Downloads\Films\Vecchi\Blade Runner\Scene" %%D in (.) do copy "%%~D\*" "E:\Temp\"

worked,but the copy is very slow. any way to improve the speed ?
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Unless you want to create a batch file to run periodically, why not just type it in at a command prompt?

You could just try and go to a command prompt in the folder you mentioned above which is under
downloads > films > Vecchi > Blade Runner > Scene

Type in "dir *.jpg /s" from the Scene folder to see if you get a bunch of files listed.

If so, then just type in from the Scene folder, "copy *.jpg /s E:\Temp"

Make sure the E: drive has enough room though.

Then after you get them all copied in there, you can work on perfecting the script substituting *.txt copy just a few test txt files to see if the get copied into the E:\Temp folder.
Avatar of Bill Prew
Bill Prew

You might try xxcopy as a way to get better performance, it has support for flattening a directory structure into a single folder during a copy via the /SX switch.  Free for personal use, but a great copy tool and worth the money for the professional use version.

~bp
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account