传递路径以空格作为参数来bat文件 [英] Pass path with spaces as parameter to bat file
问题描述
我有一个简单的蝙蝠脚本,从已知目录将文件复制到目录中用户给定。如何传递路径(它可能包含空格)给我的脚本和xcopy命令使用它?
在我的code,我有以下
:READ_PWA_PATH
如果%1==(
REM设置默认路径
设置PWA_PATH =C:\\ Program Files文件\\ PWA
REM
回声您还没有指定您的PWA URL。
回声默认会假设:C:\\ Program Files文件\\ PWA。
选择/ C:YN / M:你要继续[Y]或取消脚本[N]?
IF ERRORLEVEL == 2 GOTO取消
IF ERRORLEVEL == 1 GOTO READ_WSS_SERVER_EXTENSIONS_PATH
GOTO END
)其他(
设置PWA_PATH =%1
)
如果我只是调用脚本我得到以下错误:
C:\\项目\\设置> INSTALL.CMDC:\\ Program Files文件(x86)的-----------------
安装脚本
-----------------文件是在这个时候意外。
C:\\项目\\设置>
有趣的。我喜欢收集有关报价在cmd中/命令处理引号的。
您特定的脚本被用1%而不是%1固定!!!
通过增加一个回显(或摆脱回声关闭的),你可以很容易地发现了这一点。
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 Files\PWA"
rem
echo You have not specified your PWA url.
echo Default will be assumed: C:\Program Files\PWA.
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:\Projects\Setup>install.cmd "C:\program files (x86)"
-----------------
SETUP SCRIPT
-----------------
files was unexpected at this time.
C:\Projects\Setup>
Interesting one. I love collecting quotes about quotes handling in cmd/command.
Your particular scripts gets fixed by using %1 instead of "%1" !!!
By adding an 'echo on' ( or getting rid of an echo off ), you could have easily found that out.
这篇关于传递路径以空格作为参数来bat文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!