在 Windows .cmd 文件或批处理文件的路径中设置一个路径变量 [英] Set a path variable with spaces in the path in a Windows .cmd file or batch file

查看:30
本文介绍了在 Windows .cmd 文件或批处理文件的路径中设置一个路径变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是脚本编写新手,无法使用此脚本.如果我将文件移动到一个没有空格的路径,我可以,但如果可以的话,我希望它可以使用该空间.

I'm new to script writing and can't get this one to work. I could if I moved the files to a path without a space in it, but I'd like it to work with the space if it could.

我想将一堆 Office 更新提取到一个带有 .cmd 文件的文件夹中.为了使批处理文件在任何计算机上都可用,我设置了一个路径变量,我只需在一个地方更改它即可在另一台机器上运行它.问题是路径中有一个空格.如果我在定义中的路径周围加上引号,cmd.exe 会在附加文件名和开关之前将它们放在路径周围,并且批处理失败并显示命令行语法错误".如果没有引号,它会失败并显示不是内部或外部命令、可运行的程序或批处理文件."

I want to extract a bunch of Office updates to a folder with a .cmd file. To make the batch file usable on any computer, I set a path variable which I only have to change in one place to run it on another machine. The problem is that the path has a space in it. If I put quotes around the path in the definition, cmd.exe puts them around the path before it appends the filename and switches and the batch fails with "Command line syntax error." Without quotes, it fails with, "is not recognized as an internal or external command, operable program, or batch file."

为了测试,我使用了帮助开关,直到或如果我可以让它工作.我可以使用 8.3 文件/文件夹名称(例如我的文档作为 MyDocu~1)来完成,但可以用不同的方式完成吗?

For testing, I'm using the help switch until or if I can get it working. I can do it using an 8.3 file/folder name (e.g. My Documents as MyDocu~1), but can it be done a different way?

推荐答案

试试这个:

SET MY_PATH=C:Folder with a space

"%MY_PATH%MyProgram.exe" /switch1 /switch2

这篇关于在 Windows .cmd 文件或批处理文件的路径中设置一个路径变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆