将带有空格的路径作为参数传递给 bat 文件 [英] Pass path with spaces as parameter to bat file
问题描述
我有一个简单的 bat 脚本,可以将文件从已知目录复制到用户指定的目录.如何将路径(可能包含空格)传递给我的脚本并将其与 xcopy 命令一起使用?
I have a simple bat script that copies files from an known directory to a directory given by the user. How can I pass the path (it might contain spaces) to my script and use it with the xcopy command?
在我的代码中,我有以下内容
In my code i have the following
:READ_PWA_PATH
if "%1" == "" (
rem Set default path
set PWA_PATH="C:Program FilesPWA"
rem
echo You have not specified your PWA url.
echo Default will be assumed: C:Program FilesPWA.
choice /C:YN /M:"Do you wish to continue [Y] or cancel the script [N]?"
IF ERRORLEVEL ==2 GOTO CANCEL
IF ERRORLEVEL ==1 GOTO READ_WSS_SERVER_EXTENSIONS_PATH
GOTO END
) else (
set PWA_PATH=%1
)
如果我只是调用脚本,我会收到以下错误:
If I simply call the script I get the following error:
C:ProjectsSetup>install.cmd "C:program files (x86)"
-----------------
SETUP SCRIPT
-----------------
files was unexpected at this time.
C:ProjectsSetup>
推荐答案
有趣的一个.我喜欢收集有关在 cmd/command 中处理引号的引号.
Interesting one. I love collecting quotes about quotes handling in cmd/command.
您的特定脚本通过使用 %1 而不是 "%1" 得到修复!!!
Your particular scripts gets fixed by using %1 instead of "%1" !!!
通过添加一个echo on"(或去掉一个 echo off),您可以很容易地找到它.
By adding an 'echo on' ( or getting rid of an echo off ), you could have easily found that out.
这篇关于将带有空格的路径作为参数传递给 bat 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!