Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Quoted path with space in it still results in error  (Read 4131 times)

0 Members and 1 Guest are viewing this topic.

No_hope_without_snacks

    Topic Starter


    Starter

    • Experience: Beginner
    • OS: Unknown
    Quoted path with space in it still results in error
    « on: August 21, 2012, 04:58:59 AM »
    Hello All,

    Please help me with this.



    The command line below which renames the files in a folder and subfolder works.


    for /r C:\test1 %X in ("1106*atched randomdates*.sps") do (ren "%X" "1206*.sps")


    When I change the path name to one that has a space in it the syntax no longer works even when I put quotes around the path as in below.


    for /r “C:\test 1” %X in ("1106*atched randomdates*.sps") do (ren "%X" "1206*.sps")

    I get the error message 1” was unexpected at this time.

    Why is this and how can I fix it?

    foxidrive



      Specialist
    • Thanked: 268
    • Experience: Experienced
    • OS: Windows 8
    Re: Quoted path with space in it still results in error
    « Reply #1 on: August 21, 2012, 05:50:24 AM »
    for /r has bugs when including a path.

    Use this instead:

    Code: [Select]
    for /f "delims=" %a in ('dir "C:\test 1\1106*atched randomdates*.sps" /b') do ren "%~fa" "1206*.sps"

    No_hope_without_snacks

      Topic Starter


      Starter

      • Experience: Beginner
      • OS: Unknown
      Re: Quoted path with space in it still results in error
      « Reply #2 on: August 21, 2012, 09:51:09 AM »
      I appreciate this. It doesn't quite work as I keep getting the error file not found. The section of the code that says *atched randomdates*.sps" is there to find files with these characters (along with any other characters) in their names. As such it isn't a part of the directory structure as such.


      But more to the point. I'd be most grateful if you or anyone else could show me a way around this bug you mentioned if at all possible. The code I have works perfectly except where the folder name has a space in it. Isn't there any way at all to deal with this so I can use the code I already have? . Of course when I remove the space it works but the folders the code will apply to will have spaces in their names. I have seen some forum discussions where they suggest setting the path to a variable name and then using the variable name in the path but this doesn't work either. For example,

      set The_Path = C:\test 1

      for /r "The_Path" %X in ("1106*atched candidates*.sps") do (ren "%X" "1206*.sps")



      can this idea be built upon and made workable? Or any other solution provided please?



      Sidewinder



        Guru

        Thanked: 139
      • Experience: Familiar
      • OS: Windows 10
      Re: Quoted path with space in it still results in error
      « Reply #3 on: August 21, 2012, 09:59:47 AM »
      I was not aware that for /r had bugs, but you can quote the quote and my testing shows that it works:

      Code: [Select]
      for /r """C:\test 1""" %X in ("1106*atched randomdates*.sps") do (ren "%X" "1206*.sps")

       8)
      The true sign of intelligence is not knowledge but imagination.

      -- Albert Einstein

      foxidrive



        Specialist
      • Thanked: 268
      • Experience: Experienced
      • OS: Windows 8
      Re: Quoted path with space in it still results in error
      « Reply #4 on: August 21, 2012, 11:28:34 PM »
      I appreciate this. It doesn't quite work as I keep getting the error file not found. The section of the code that says *atched randomdates*.sps" is there to find files with these characters (along with any other characters) in their names. As such it isn't a part of the directory structure as such.

      It's part of the file system.  I forgot to add /s after the /b
      That recurses through folders.