Re: Can't get DOS "for" loop to return full filenames with spaces

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



dtronvig wrote:

"VanguardLH" wrote:

dtronvig wrote:

I'm trying to set up a DOS batch file (in XP) to decode all the MP3
files in a directory using a "for" loop. I just can't figure out
how to get the "for" command to return anything beyond the first
space in a filename. To simplify things, I tried this right in the
Command window:

The directory contains files "a 1.mp3", "b 1.mp3" and "c 1.mp3". I
enter:

for /f usebackq %f IN (`dir /b *.mp3`) do dir "%f"

The resulting echoed commands are

dir "a"
dir "b"
dir "c"

and of course the resulting directory listings are empty.

So `dir /b *.mp3` is producing the list of full filenames, but the
"for" command is just passing along the filenames up to the first
space.

Another problem is parsing. The output of the fileset (your `dir`
output) uses spaces to delimit each item in the list. Yet you have
spaces in the item's strings in that list. So when the list gets parsed
based on spaces to pipe into the 'do' clause of the 'for' command, each
space-delimited item gets passed out. You might get around this parsing
problem by specifying a different delimiter than space and tab (which
are the defaults) by using the options parameter. As I recall, if the
delims option is used, it must be the last one inside the quoted options
string.

So try in the command line (I used the semicolon but you can pick
something else) ... in a batch file use:

for /f "usebackq delims=;" %%f in (`dir /b *.txt`) do dir "%%f"

Well, what I was aiming for turned out to be:

for %%a in (*.mp3) do call D:\Programs\Lame\Lame.exe --decode "%%a"

The "do dir" version was just an attempt to clarify what was being passed.

I now know more about "for /F" than I need to at the moment, but I'll be
tempted to use it for more complex operations in the future.

Then it comes down to using the default parsing characters of space and
tab for the 'in' list created by the specified filespec (which, for you,
was the output of a dir command). There were spaces in the items added
to the list, and the default parsing uses the space character. That's
why one of my suggestions was to specify a different delimiter character
to insert between each item returned by the filespec.
.



Relevant Pages

  • Re: Playing MP3 in login script
    ... I would do a google search for command line mp3 player (mpg321 should ... It should work with a simple batch file, ...
    (microsoft.public.scripting.vbscript)
  • Re: log off command
    ... I simply execute the batch file and let them play... ... If it's by the hour you don't need a script. ... You can logoff a sessionname or a session ID in each case you have to ... Is it possible to issue the command from user1's logon to logoff ...
    (microsoft.public.windowsxp.basics)
  • Re: log off command
    ... I simply execute the batch file and let them play... ... If it's by the hour you don't need a script. ... You can logoff a sessionname or a session ID in each case you have to ... Is it possible to issue the command from user1's logon to logoff ...
    (microsoft.public.windowsxp.basics)
  • Re: log off command
    ... SOON 3600 LOGOFF %ID2% ... If it doesn't work please post what the "at" command returns if you run it ... after the batch file and please again describe when it does not work. ... Matija Hrovat ...
    (microsoft.public.windowsxp.basics)
  • Re: Looking for binary file xfer from TRSDOS6/LSDOS6
    ... be wrong with the command line parameters. ... By deleting a few lines from the start of the batch file, ... FTII will eventually reach and transfer the files it just claimed were ... and my list is longer than the buffer can handle. ...
    (comp.sys.tandy)