![]() |
![]() |
![]() |
|||||
![]() |
![]() |
![]() |
![]() |
![]() |
|||
| Welcome
to Tech Support Forum home to more then 136,000 problems solved. Issues
have included: Spyware, Malware, Virus Issues, Windows, Microsoft,
Linux, Networking, Security, Hardware, and Gaming Getting your
problem solved is as easy as: 1. Registering for a free account 2. Asking your question 3. Receiving an answer Registered members: * See fewer ads. * And much more..
|
| Want to know how to post a question? click here | Having problems with spyware and pop-ups? First Steps |
|
|||||||
| Programming A discussion forum for programs and programming used in tech-related businesses. |
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) |
|
Registered User
Join Date: Jul 2009
Posts: 6
OS: Windows XP
|
Executing .bat file in multiple subdirectories
I have a pair of .bat files set up to modify and convert multiple .tif images in a single directory.
It's not working right. I also need to set it up to run in multiple subdirectories. (It's a large-scale image conversion I'm working on) The first .bat file simply executes a for command: Code:
for %%f in (*.tif) do call echo.bat %%f Code:
set file=&~n1 It's working well, except for a couple of things: on Angel.tif, and Bee.tif it works fine... but then it hits Bird House.tif and the space messes up the string parser, and it ends up returning just 'Bird' instead of 'Bird House' How do I get the spaces to stay in there? The "set file=%file:~0,-4%" doesn't work either, because that gets messed up by the space as well. Also, I need this .bat to function not just in the directory it's put in, but instead I need to modify it somehow to run in each of the subdirectories 2-4 folders deeper than the current directory, and do the same thing to the files in those subdirectories. And... some of the folders have white space in their names too. Does anyone know how to make this all work? Last edited by illyume; 07-01-2009 at 05:07 PM. |
|
|
|
| Important Information |
|
Join the #1 Tech Support Forum Today - It's Totally Free!
TechSupportForum.com is a leading support website for your computer needs. We offer free, friendly and personalized computer support. Why pay to have your computer fixed when you can do it for free. Join TechSupportforum.com Today - Click Here |
|
|
#2 (permalink) |
|
Tech Hardware Team
Join Date: Jul 2005
Posts: 1,461
OS: Windows
|
Re: Executing .bat file in multiple subdirectories
for /F "usebackq delims=" %k IN (`dir *.tif /s /b`) DO @echo %~dpnk
here i just @echoed it to the display, try it at the command prompt and it looks like doing a fancy dir *.tif and will also show all the subdirectory contents too. so in example if i was using irfanview (which, by the way, does batch conversion etc) to process a directory tree of tif files, like your doing, then i would use it's command line version like this... for /F "usebackq delims=" %k IN (`dir *.tif /s /b`) DO c:\program files\i_view32.exe %~dpnk /convert=%~dpk\*.jpg (not exactly correct, would have to tell iview it's getting a tif extension, but you get the idea). so, up to you whether you use it directly or call the next batch file. %k (full path) %~dpnk (path, no extention) %~dpk (only shows directories part that have k files but not filenames)
__________________
|
|
|
|
|
|
#3 (permalink) |
|
Registered User
Join Date: Jul 2009
Posts: 6
OS: Windows XP
|
Re: Executing .bat file in multiple subdirectories
Thank you so much! I haven't quite figured out what that code does, but I've been able to put it in my .bat files, adjusted a few things, and it's working just as I wanted it to now!
This is great! :D Err, scratch that. It's almost working perfectly. Then I get to "Bird House.tif" and it does the bad '*** do I do with whitespace!?' thing again. At least this time it's a little further in the function call, and there's only two spots I'm going to have to change things further, it looks like. So, here's the first place where it errors: ![]() And there's another line that I'm pretty sure will do the same thing: convert img_inside.png img_edging.png -background none -flatten %file%.png How do I fix this? Last edited by illyume; 07-02-2009 at 11:45 AM. |
|
|
|
|
|
#6 (permalink) |
|
Registered User
Join Date: Feb 2009
Posts: 3
OS: Vista
|
Re: Executing .bat file in multiple subdirectories
The following biterscript may simplify the job. It will convert all .tif files in C:\Winter and its subfolders, sub-subfolders, etc.
As Squashman correctly suggested, I am enclosing fully qualified file names in double quotes, since file names or folder names may contain spaces and other special characters. Code:
# script convert.txt
# Get a list of .tif files.
var str list ; lf -n "*.tif" "C:\Winter" > $list
# Convert one file at a time.
while ($list <> "")
do
var str file ; lex "1" $list > $file
system convert ("\""+$file+"\"") "OTHER OPTIONS AND ARGUMENTS"
done
Code:
script convert.txt Patrick |
|
|
|
![]() |
| Thread Tools | |
|
|