Saving all files from subdirectories to a main directory

Here is a quick batch file that will go through all subdirectories in a directory tree and copy files, ie photos, to another directory.  This works well with the Saving Vox photos post that I did recently.

——————————————————–

for /f %%a in (‘dir /b *_files’) do call :process “%%a” “%%~dpa”
goto :eof

:process
cd %1
copy *.jpg c:\TARGETDIR
cd ..

——————————————————–

The main points in this are the “_files in the dir command and the C:\TARGETDIR in the copy command.  In my example case, Firefox and iMacros created a bunch of directories called (something)_files, so I want to loop through all of those.  The batch starts by building a list of all of these directory names then it starts a loop process to work through them.

The subroutine “process” changes the current directory to the subdirectory and then copies all of the JPG (picture) files up to C:\TARGETDIR.  You would call this something else, but make sure it’s created before you start.

Running instructions –

After making appropriate changes, you save this batch file in the parent directory of the subdirectories you want to read from.  I call it something simple like “DOIT.BAT” and then I shell out to DOS and run it.

Again, this works for me – there are probably other ways to achieve the same results.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s