View Single Post
  #2  
Old 10-04-2006, 03:08
Joe Forster/STA's Avatar
Joe Forster/STA Joe Forster/STA is offline
Senior forum member
 
Join Date: Nov 2000
Location: Hungary
Posts: 9,836
Thanks: 20
Thanked 342 Times in 224 Posts
Joe Forster/STA is on a distinguished road
That %%f is being used as a special variable: the loop variable. As you can see it has a different syntax already: instead of %envvarname%, it's called %%x; percent mark only in the front and only a single letter allowed.

Mind you, DOS/Windows batch language is a completely ill-designed pile of shit. There's an alternative called 4DOS and 4NT but it has its own, "proprietary" language. When I do batch files I use GnuWin32, the native 32-bit Windows executables of the standard GNU tools (from Unix). (If you need the EXE's only, tell me.)

With the GNU tools, it's not much easier, though - again, because of the incredible clumsiness of the DOW/Windows batch language:
- As the inside of the loop consists of several instructions, you gotta make a subroutine. Such a construct cannot be defined in batch files, therefore, you need to make the batch file call itself as some kind of poor man's subroutine call.
- You need to enclose filenames into quotation marks so that filenames with spaces inside won't get split apart and processed as multiple command line parameters. However, the batch file does get the quotation marks, as well. If you try to compare strings that may possibly have spaces inside, you need to enclose them into quotation marks, otherwise you'll get a syntax error; "IF whatever this file name is == whatever" just doesn't work! However, if the string is already enclosed into quotation marks - because that's how you passed it to the batch -, you'll just unquote them and get back to the previous problem. Therefore, I use no spaces in filenames (convert them to underscores instead)!
- You cannot execute a command and then include its standard output as part of another command. This means, you cannot set an environment variable to a value that arrives via the standard output of a command. Therefore, you gotta create a temporary batch file, with a SET command in it, append the standard output of the command to this batch file and run the batch file, to have the value put into the variable. UGLY!

It's worth learning how to use the standard GNU tools as they are a standard, well-designed, continuously maintained sets of general purpose tools, and they will come very handy anyway if you need to switch to Unix some time (i.e. when Micro$oft gets bankrupt and Linux will become the only major OS in town, HAHAHA! ).

As for the actual problem, here's a sample batch file for you; it may give you syntax errors, though, I haven't tested it. I'm currently into DVD-ripping with GordianKnot and have developed quite a few similar, but much more complicated batch files - for automized audio conversion with BeSweet or LAME - that use the GNU tools and work similarly to GNU tools (with respect to command line options). If you're interested, contact me via E-mail!

if `%1` == `` goto all
echo `%1` | tr -d "\042`" | sed "s/\.mp3$/.wav/I;s/^/set INPUTNAME=/" > %TEMP%\whatever.bat
call %TEMP%\whatever.bat
del %TEMP%\whatever.bat
lame --decode %1 "%FILENAME%"
:all
for %%f in (*.mp3) do call %0 "%%f"
__________________
Joe Forster/STA
For more information, see the FileForums forum rules and the PC Games forum FAQ!
Don't contact me via E-mail or PM to ask for help with anything other than patches (or software in general) done by me, otherwise your request may be deleted without any reply!
Homepage: http://sta.c64.org, E-mail: [email protected]; for attachments, send compressed (ZIP or RAR) files only, otherwise your E-mail will bounce back!

Last edited by Joe Forster/STA; 10-04-2006 at 03:51.
Reply With Quote