windows .bat 文件 - cd 到名称中带有空格并使用变量的目录?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2977513/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
.bat file - cd to a directory with a space in its name and also using a variable?
提问by splatback
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.
我写了一个快速的 .bat 文件,读取用户键入的目录的名称,我将该变量存储在一个变量中,然后我想实际 cd 到该目录。
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.
例如,我已经用简单的目录(如“C:”)对其进行了测试,结果奏效了。但是,当我处理用户输入诸如“C:\Documents and Settings\Desktop”之类的内容时,我无法执行 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 overcome this?
我不断收到“系统找不到指定的路径”的错误消息,即使我使用的是全名。有谁知道如何克服这个?
采纳答案by aviraldg
set /p DIR="path:"
cd %DIR%
Works just fine.
工作得很好。
回答by Philippe Leybaert
How about:
怎么样:
cd "%directory%\sampleFolder"
回答by Mark Baker
@ECHO OFF
ECHO Enter Directory
SET/p directory=
CHDIR %directory%
Works for me (Windows 7) but should work for XP/Vista/etc
适用于我(Windows 7)但应该适用于 XP/Vista/etc