batch file problem

Status
Not open for further replies.

glenm

Seniorius Lurkius
2
Hi when running the following within a batch file from my C:\Documents and Settings directory the program does not seem to handle the spaces correctly. It thinks its dealing with a list of "C:\Documents" "and" then "Settings". It work correctly on some windows machines but not others.

The program is

for /d %%X in ("%cd%\*") do echo %%X

Does anyone know the fix ??

Thanks
 

MooseAreFun

Ars Legatus Legionis
10,827
Subscriptor
I played about with this on Vista, and the usual solution is to put quotes around the directory name, but you have done that in the "%CD%\*" part. It works fine. If I take those quotes away, then I get the problem you describe of mishandling the spaces.

Do you know what's different between the machines that work and the ones that don't? Different OS or anything? Is there any chance you are running a version of the batch file without the quotes by mistake?
 

devjames

Wise, Aged Ars Veteran
107
How about this instead:
Code:
for /r "c:\documents and settings" %i in (.) do @echo %i

We used to have some Compaqs that had a screwed cmd.exe. You could tell every time because
Code:
echo.|time
would fail.

Weird.

One other thought: extensions can be elabled/disabled in the registry. See the output of 'cmd.exe /?' for more.

If you put
Code:
setlocal enableextensions enabledelayedexpansion
in your batch file and it starts working then the registry stuff is probably why.
 
Status
Not open for further replies.