Windows 7: Batch-Operation: Recursive File Processing?

Hi,
I have the following problem:
Some 1000 files that need to be processed by a command line batch.
Files are organized in a large directory tree structure.
The idea is to start a batch file (.bat) which will start at root level, looking for a certain file type (*.dng), take these files, process them (extract JPG), store output (JPG) to the same folder location and loop through all directories down to the last file doing the same thing (recursive processing).
Is there a batch script (DOS) available?
Thanks.
go4javaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

t0t0Commented:
yes! you need the following skeleton batch code and insert the line that actually processes your files (whatever that may be).


@echo off
setlocal enabledelayedexpansion

for /r "c:\" %%a in (*.dng) do (
   set filename=%%~nxa
   set filepath=%%~dpa
   ::
   :: This is where your code goes which processes the file held in the variable !filename!
   :: The path of the file is held in the variable !filepath!
   ::
)

0
t0t0Commented:
Incidentally, where I have specified '"c:\"' in the above code, replace that with the root folder of your directory structure where all your DNG files are.

So, if all your DNG files are rooted off C:\DNGFILES\ then you need to code the FOR line like this:

   for /r "c:dngfiles\" %%a in (*.dng) do (
0
go4javaAuthor Commented:
...I get the message "system cannot find the drive"...
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

t0t0Commented:
interesting..... please hold on a mo....
0
go4javaAuthor Commented:
...just to add the ACTION:

Each hit of *.dng should convert to *.jpg (and delete the original *.dng):

exiftool -copy1:previewimage -b input-image.dng > output-image.jpg

BR
0
t0t0Commented:
Please look at the following skeleton code carefully.

I have included som e sample code so you can see the variable names in action.

Also, if you don't want to use the following method:

   "!filepath!\!filename!"

then you can simply CD into the folder first, then just use the filename etc as in the following example:

   cd "!filepath!"
   
   if not exist "new folder" (
      md "new folder"
   )

   copy "!filename!" "new folder"

as you can see, CD-ing into the folder makes a huge difference.

NOTE: Don't forget to change the '"c:\test\*.DNG"' in the FOR-line to suit your own needs.




@echo off
setlocal enabledelayedexpansion

for /f "tokens=*" %%a in ('dir /a-d /b /s "c:\test\*.DNG"') do (
   set filename=%%~nxa
   set filepath=%%~dpa
   set filepath=!filepath:~0,-1!

   rem
   rem This is where your code goes which processes the file held in the variable FILENAME
   rem The path of the file is held in the variable FILEPATH
   rem
   
   rem
   rem Below is some example code
   rem
   rem Bear in mind I have removed the trailing backslash character off FILEPATH
   rem as this makes it easier to use FILEPATH - see below
   rem
   
   rem
   rem Notice the use of the backslash character
   rem NOTICE the use of double-quotation marks around filenames and paths
   rem
   
   echo.
   echo Found file: !filename!
   echo In path: !filepath!
   echo.
   
   if not exist "!filepath!\NEW FOLDER" (
      echo Creating !filepath!\NEW FOLDER
      md "!filepath!\NEW FOLDER"
   )

   echo Copying !filename! to !filepath!\NEW FOLDER
   copy /y "!filepath!\!filename!" "!filepath!\new folder" >nul
)
exit /b
0
t0t0Commented:
Reposted in the Code snippet box

.

@echo off
setlocal enabledelayedexpansion

for /f "tokens=*" %%a in ('dir /a-d /b /s "c:\test\*.DNG"') do (
   set filename=%%~nxa
   set filepath=%%~dpa
   set filepath=!filepath:~0,-1!

   rem
   rem This is where your code goes which processes the file
   rem held in the variable FILENAME
   rem
   rem The path of the file is held in the variable FILEPATH
   rem
   
   rem
   rem Below is some example code
   rem
   rem Bear in mind I have removed the trailing backslash
   rem character off FILEPATH as this makes it easier
   rem to use FILEPATH - see below
   rem
   
   rem
   rem Notice the use of the backslash character
   rem NOTICE the use of double-quotation marks around 
   rem filenames and paths
   rem
   
   echo.
   echo Found file: !filename!
   echo In path: !filepath!
   echo.
   
   if not exist "!filepath!\NEW FOLDER" (
      echo Creating !filepath!\NEW FOLDER
      md "!filepath!\NEW FOLDER"
   )

   echo Copying !filename! to !filepath!\NEW FOLDER
   copy /y "!filepath!\!filename!" "!filepath!\new folder" >nul
)

exit /b

Open in new window

0
t0t0Commented:
try this:


@echo off

set rootfolder=c:\dngfiles

for /f "tokens=*" %%a in ('dir /a-d /b /s "%rootfolder%\*.DNG"') do (
   exiftool -copy1:previewimage -b "%%~dpnxa" > "%%~dpna.jpg"
)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
go4javaAuthor Commented:
Thank you, I'll try.

Q: What is the meaning of the code:

"  if not exist "!filepath!\NEW FOLDER" (
      echo Creating !filepath!\NEW FOLDER
      md "!filepath!\NEW FOLDER"
   )

   echo Copying !filename! to !filepath!\NEW FOLDER
   copy /y "!filepath!\!filename!" "!filepath!\new folder" >nul"

Each level of directory structure will have 0 to n DNG files, so what's the reason behind creating new folders?

BR
0
t0t0Commented:
i know...

i was just showing you some example code....on how to use the variables
0
t0t0Commented:
i have to nip out now... will not be able to respond for several hours
0
go4javaAuthor Commented:
SOLUTION:

Step 1 - Collect all and full DNG paths and write list to test.txt

dir /b /s *.dng > c:\test.txt

Schritt 2 - Loop test.txt and extract high-res JPEG images from raw DNG files (using fantastic tool dcraw.exe)

FOR /f "usebackq delims==" %%a IN (c:\test.txt) DO dcraw.exe -e "%%a"

Your loop will probably achieve the same thing, so I'll assign the points right know...

Thanks and best regards
0
t0t0Commented:
Thank you.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.