windows 批处理中的文件名、目录名或卷标语法不正确

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24782826/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 11:39:39  来源:igfitidea点击:

The filename, directory name, or volume label syntax is incorrect inside batch

windowscmd

提问by Debajyoti Das

When I am running the following inside batch....

当我在批处理中运行以下内容时....

set PATH='C:\Users\DEB\Downloads.1.1.0.4'
cd !PATH!

I get error "The filename, directory name, or volume label syntax is incorrect"

我收到错误“文件名、目录名或卷标语法不正确”

Update: There are the solutions that worked for me.

更新:有适合我的解决方案。

  • Don't use PATHas a var name
  • set it as "myPATH=C:\Users\DEB DAS\Downloads\10.1.1.0.4"
  • 不要PATH用作 var 名称
  • 将其设置为 "myPATH=C:\Users\DEB DAS\Downloads\10.1.1.0.4"

采纳答案by TessellatingHeckler

set myPATH="C:\Users\DEB\Downloads.1.1.0.4"
cd %myPATH%
  • The single quotes do not indicate a string, they make it starts: 'C:\instead of C:\so

  • %name%is the usual syntax for expanding a variable, the !name!syntax needs to be enabled using the command setlocal ENABLEDELAYEDEXPANSIONfirst, or by running the command prompt with CMD /V:ON.

  • Don't use PATH as your name, it is a system name that contains all the locations of executable programs. If you overwrite it, random bits of your script will stop working. If you intend to change it, you need to do set PATH=%PATH%;C:\Users\DEB\Downloads\10.1.1.0.4to keep the current PATH content, and add something to the end.

  • 单引号不表示字符串,它们使它开始:'C:\而不是C:\这样

  • %name%是扩展变量的常用语法,!name!需要setlocal ENABLEDELAYEDEXPANSION首先使用命令启用该语法,或者通过运行命令提示符CMD /V:ON

  • 不要使用 PATH 作为您的名称,它是一个包含可执行程序所有位置的系统名称。如果覆盖它,脚本的随机部分将停止工作。如果你打算改变它,你需要做的set PATH=%PATH%;C:\Users\DEB\Downloads\10.1.1.0.4是保持当前的 PATH 内容,并在最后添加一些东西。