Results 1 to 4 of 4

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

  1. #1
    Join Date
    Aug 2006
    Posts
    332

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

    I want to setup a dos batch file in XP to decode all the mp3 files in a directory using a "for" loop. I am not able to 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 Windows:

    Th is 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.

    What else is to be done? Thanks

  2. #2
    Join Date
    Jan 2006
    Posts
    830

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

    Can you try to only switch from "DOS" to Command Prompt" to avoid being corrected and having the diffs explained to you.

  3. #3
    Join Date
    Oct 2005
    Posts
    792
    Well, in the current directory try to do the below:
    for %f in (*.txt) do echo "%f"

    In a specified directory:
    for %f in (C:\FolderName\*.txt) do echo "%f"
    for %f in ("C:\Folder Name\*.txt") do echo "%f"

    No quotes in echoed results:
    for %f in ("C:\Folder Name\*.txt") do echo %f

  4. #4
    Join Date
    Nov 2005
    Posts
    930
    You can also try to do it in 2 parts, just follow the below suggestions:
    dir /b *.mp3 >C:\mp3list.txt
    for /f "usebackq delims=" %A in (c:\mp3list.txt) do echo "%A"

    You can also use FOR /R if you want to recurse through folders:
    for /r C:\windows\ %a in (*.txt) do echo %a

Similar Threads

  1. Replies: 7
    Last Post: 18-02-2012, 04:19 PM
  2. Replies: 1
    Last Post: 19-10-2009, 09:48 AM
  3. Replies: 3
    Last Post: 02-02-2008, 08:58 AM
  4. Replies: 2
    Last Post: 07-12-2006, 05:56 PM
  5. Replies: 14
    Last Post: 13-07-2005, 08:28 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,483,585.01961 seconds with 17 queries