开发者

.bat file - cd to a directory with a space in its name and also using a variable?

ive written a quick .bat file that reads in the name of a directory typed in by the user, i store that variable in a variable, and then i want to actually cd to that directory.

i've tested it out with simple directories like "C:," for instance, and that works. however, when i'm dealing with the user entering in something like "C:\Documents and Settings\Desktop," i can't do cd %directory%\sampleFolder.

i keep getting an error of "the system cannot find the path specified," even though i'm using the full name. anyone know how to ov开发者_运维百科ercome this?


How about:

cd "%directory%\sampleFolder"


set /p DIR="path:"
cd %DIR%

Works just fine.


@ECHO OFF
ECHO Enter Directory
SET/p directory=
CHDIR %directory%

Works for me (Windows 7) but should work for XP/Vista/etc

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜