go4java
asked on
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.
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.
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 (
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 (
ASKER
...I get the message "system cannot find the drive"...
interesting..... please hold on a mo....
ASKER
...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
Each hit of *.dng should convert to *.jpg (and delete the original *.dng):
exiftool -copy1:previewimage -b input-image.dng > output-image.jpg
BR
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
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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
i know...
i was just showing you some example code....on how to use the variables
i was just showing you some example code....on how to use the variables
i have to nip out now... will not be able to respond for several hours
ASKER
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
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
Thank you.
@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!
::
)