Re: Multiple File Conversions via Batch File

Tech-Archive recommends: Fix windows errors by optimizing your registry



someone@xxxxxxxxxxxxxxxxxxxxxx wrote:

Hello,
I am attempting to convert multiple .wav files to the .flac format via a batch script. I know that this can be done with numerous software implementations automatically for me; however, i am interested to understand how to create a script to perform my purpose and since this function is useful, what the hey! I am rather new to batch files but would appreciate any help. TIA

My process thus far has been the following:

I edited the file type .wav via Tools>Folder Options>File Types I added an option for "Encode to Flac" and pointed this at my "flac-convert.bat %1"

Essentially this works fine; The script runs and encodes one file with ease. At this point my script was:
@ECHO OFF
C:\"Program Files\flac\bin\flac.exe -8 %1


However, when I highlighted multiple .wav files in Explorer and click my "Encode" option multiple instances of the batch file are run. I attempted to solve this with the following code:

@ECHO OFF
:LOOP
FOR %%1 IN (.) DO C:\"Program Files"\flac\bin\flac.exe -8 %%1
SHIFT
IF "%1" == "" GOTO END
GOTO LOOP
:END

When I ran this code I hit another stumbling block. The code was parsing the %1 differently than it had in my original instance where flac was run directly. The filenames contained are something like My_alto-sax_solo.wav When I ran the first script this was parsed fine and the wav file was encoded; but, when the flac.exe was run from within the FOR loop the input file is claimed to be invalid.

So my question is two part:

1)Understanding the parsing of text within a Batch File:

How does passing a command within a FOR alter the way arguments are passed to it?

and

2) Is it possible to only run one instance of the batch file via some setting within Windows?



- - - - - - - - begin screen capture WinXP Pro SP2 - - - - - - - C:\cmd>for %a in (\windows\Media\*.wav) do @echo/"C:\Program Files\flac\bin\flac.exe" -8 "%~fa"
"C:\Program Files\flac\bin\flac.exe" -8 "C:\WINDOWS\Media\chimes.wav"
"C:\Program Files\flac\bin\flac.exe" -8 "C:\WINDOWS\Media\chord.wav"
"C:\Program Files\flac\bin\flac.exe" -8 "C:\WINDOWS\Media\ding.wav"
"C:\Program Files\flac\bin\flac.exe" -8 "C:\WINDOWS\Media\notify.wav"
"C:\Program Files\flac\bin\flac.exe" -8 "C:\WINDOWS\Media\recycle.wav"
"C:\Program Files\flac\bin\flac.exe" -8 "C:\WINDOWS\Media\ringin.wav"
"C:\Program Files\flac\bin\flac.exe" -8 "C:\WINDOWS\Media\ringout.wav"
"C:\Program Files\flac\bin\flac.exe" -8 "C:\WINDOWS\Media\start.wav"
"C:\Program Files\flac\bin\flac.exe" -8 "C:\WINDOWS\Media\tada.wav"
"C:\Program Files\flac\bin\flac.exe" -8 "C:\WINDOWS\Media\Windows XP Balloon.wav"
"C:\Program Files\flac\bin\flac.exe" -8 "C:\WINDOWS\Media\Windows XP Battery Critical.wav"
"C:\Program Files\flac\bin\flac.exe" -8 "C:\WINDOWS\Media\Windows XP Battery Low.wav"
"C:\Program Files\flac\bin\flac.exe" -8 "C:\WINDOWS\Media\Windows XP Critical Stop.wav"
"C:\Program Files\flac\bin\flac.exe" -8 "C:\WINDOWS\Media\Windows XP Default.wav"
"C:\Program Files\flac\bin\flac.exe" -8 "C:\WINDOWS\Media\Windows XP Ding.wav"
"C:\Program Files\flac\bin\flac.exe" -8 "C:\WINDOWS\Media\Windows XP Error.wav"
"C:\Program Files\flac\bin\flac.exe" -8 "C:\WINDOWS\Media\Windows XP Exclamation.wav"
"C:\Program Files\flac\bin\flac.exe" -8 "C:\WINDOWS\Media\Windows XP Hardware Fail.wav"
"C:\Program Files\flac\bin\flac.exe" -8 "C:\WINDOWS\Media\Windows XP Hardware Insert.wav"
"C:\Program Files\flac\bin\flac.exe" -8 "C:\WINDOWS\Media\Windows XP Hardware Remove.wav"
"C:\Program Files\flac\bin\flac.exe" -8 "C:\WINDOWS\Media\windows xp information bar.wav"
"C:\Program Files\flac\bin\flac.exe" -8 "C:\WINDOWS\Media\Windows XP Logoff Sound.wav"
"C:\Program Files\flac\bin\flac.exe" -8 "C:\WINDOWS\Media\Windows XP Logon Sound.wav"
"C:\Program Files\flac\bin\flac.exe" -8 "C:\WINDOWS\Media\Windows XP Menu Command.wav"
"C:\Program Files\flac\bin\flac.exe" -8 "C:\WINDOWS\Media\Windows XP Minimize.wav"
"C:\Program Files\flac\bin\flac.exe" -8 "C:\WINDOWS\Media\Windows XP Notify.wav"
"C:\Program Files\flac\bin\flac.exe" -8 "C:\WINDOWS\Media\windows xp pop-up blocked.wav"
"C:\Program Files\flac\bin\flac.exe" -8 "C:\WINDOWS\Media\Windows XP Print complete.wav"
"C:\Program Files\flac\bin\flac.exe" -8 "C:\WINDOWS\Media\Windows XP Recycle.wav"
"C:\Program Files\flac\bin\flac.exe" -8 "C:\WINDOWS\Media\Windows XP Restore.wav"
"C:\Program Files\flac\bin\flac.exe" -8 "C:\WINDOWS\Media\Windows XP Ringin.wav"
"C:\Program Files\flac\bin\flac.exe" -8 "C:\WINDOWS\Media\Windows XP Ringout.wav"
"C:\Program Files\flac\bin\flac.exe" -8 "C:\WINDOWS\Media\Windows XP Shutdown.wav"
"C:\Program Files\flac\bin\flac.exe" -8 "C:\WINDOWS\Media\Windows XP Start.wav"
"C:\Program Files\flac\bin\flac.exe" -8 "C:\WINDOWS\Media\Windows XP Startup.wav"
- - - - - - - - end screen capture WinXP Pro SP2 - - - - - - - -
(watch out for line wrap)

--
Phil Robyn
University of California, Berkeley
.



Relevant Pages

  • Re: new script
    ... The caret character ^ is required when generating test.vbs ... I'm really thankfull for your help (and script). ... #echo>> c:\test.vbs ... remove them before running the batch file. ...
    (microsoft.public.windows.server.scripting)
  • Re: Windows NT Command Script problem
    ... and run a script to copy what needs to be ... >>@echo off ... >>rem END of command file ... >>operable program or batch file. ...
    (microsoft.public.windows.server.scripting)
  • Re: Creating a script to search and replace files in XP
    ... You probably need a batch file. ... How does the script know if the file is unconverted? ... Remove the word "echo" ... echo del "%old% ...
    (microsoft.public.windows.file_system)
  • Re: Help needed with Script
    ... The specification would be in the ini which will be ... There is a fairly comprehensive console command and batch file ... @echo off ... When testing your script or batch file, ...
    (microsoft.public.windows.server.general)
  • Re: Using OR in Scripting?
    ... the end of the batch file. ... echo Found ... its for a logon .bat script. ... and use 2 GOTO ...
    (microsoft.public.windows.server.scripting)