批处理脚本问题将路径作为带有空格的参数传递

批处理脚本问题将路径作为带有空格的参数传递

蝙蝠侠

@echo off

set url=D:\Download\Path with space inside

echo "%url%"

pause

输出:

C:\Users\Admin\Desktop>go
"D:\Download\Path with space inside"
Premere un tasto per continuare . . .

如果我像这样传递参数:

C:\Users\Admin\Desktop>go D:\Download\Path 里面有空格

@echo off

set url=%~1

echo "%url%"

pause

输出错误:路径不正确

C:\Users\Admin\Desktop>go D:\Download\Path with space inside
"D:\Download\Path"

请帮忙:D

答案1

使用此批处理文件

@echo off

set url=%~1

echo "%url%"

pause

您需要在“”中传递路径

C:\Users\Admin\Desktop>go "D:\Download\Path with space inside"

该命令及其输出将是:-

C:\Users\Admin\Desktop>go "D:\Download\Path with space inside"
"D:\Download\Path with space inside"

如果有效,请告诉我。

相关内容