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:
* Get free support
* Communicate privately with other members (PM).
* Removal of this message
* 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
Go Back   Tech Support Forum > The IT Pro > Programming
User Name
Password
Site Map Register Donate Rules Blogs Mark Forums Read


Programming A discussion forum for programs and programming used in tech-related businesses.

Reply
 
LinkBack Thread Tools
Old 07-01-2009, 04:53 PM   #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
The second .bat file takes that parameter, and does this:

Code:
set file=&~n1
Which should set the variable 'file' to the file's name without file extension. It then runs through a series of commands to convert the file type, set the background to transparent, and cleans up the image.

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.
illyume is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
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

Old 07-02-2009, 08:27 AM   #2 (permalink)
Tech Hardware Team
 
Stu_computer's Avatar
 
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)
__________________
Stu_computer is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 07-02-2009, 11:34 AM   #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.
illyume is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 07-02-2009, 12:06 PM   #4 (permalink)
Registered User
 
Join Date: Jul 2009
Posts: 6
OS: Windows XP


Re: Executing .bat file in multiple subdirectories

Nevermind, I'm a .bat noob. I just needed to use "%file%" instead of %file% in the calls to the file.

Anyway, thanks again for the help!
illyume is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 07-03-2009, 10:53 AM   #5 (permalink)
Tech, Networking Forums
 
Squashman's Avatar
 
Join Date: Apr 2005
Location: 1265 Lombardi Ave.
Posts: 1,148
OS: All of the above


Re: Executing .bat file in multiple subdirectories

Any time you have spaces in your path or filenames you need to use quotes.
Squashman is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 07-15-2009, 10:19 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
I have not tested it. Test it first. Save the script as C:\Scripts\convert.txt, start biterscripting ( http://www.biterscripting.com ), enter the following command.

Code:
script convert.txt

Patrick
Patrick Mc is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -7. The time now is 12:27 AM.



Copyright 2001 - 2009, Tech Support Forum
Home Tips Plus | Outdoor Basecamp | Automotive Support Forum

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85