1.

Solve : Quoted path with space in it still results in error?

Answer»

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?
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"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?


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")

Quote from: No_hope_without_snacks 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.

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


Discussion

No Comment Found