Re: Can't get DOS "for" loop to return full filenames with spaces
- From: VanguardLH <V@xxxxxxxxx>
- Date: Fri, 29 May 2009 00:24:06 -0500
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.
.
- References:
- Can't get DOS "for" loop to return full filenames with spaces
- From: dtronvig
- Re: Can't get DOS "for" loop to return full filenames with spaces
- From: VanguardLH
- Re: Can't get DOS "for" loop to return full filenames with spaces
- From: dtronvig
- Can't get DOS "for" loop to return full filenames with spaces
- Prev by Date: Outlook Express Find Message function stopped working
- Next by Date: Re: Windows XP Pro reverts to basic installed state
- Previous by thread: Re: Can't get DOS "for" loop to return full filenames with spaces
- Next by thread: Restoring Default Windows XP Registry
- Index(es):
Relevant Pages
|