开发者

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

开发者 https://www.devze.com 2023-01-02 13:58 出处:网络
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.

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

精彩评论

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