简体   繁体   English

Windows 运行找不到批处理文件

[英]Windows Run can't find batch file

I created a very simple batch file that works when I double click the file, but if I try to launch it by typing in the name of the batch file into Windows Run, Windows is unable to find it.我创建了一个非常简单的批处理文件,当我双击该文件时它可以工作,但是如果我尝试通过在 Windows Run 中输入批处理文件的名称来启动它,Windows 无法找到它。 If I type in the name of the folder containing the batch file, the folder opens up.如果我输入包含批处理文件的文件夹的名称,则会打开该文件夹。

Fairly new to coding.对编码相当陌生。 I'm going through "Automate the Boring Stuff" book我正在阅读“自动化无聊的东西”一书

Run searches the folders in your global %PATH% variable for your file.运行搜索全局%PATH%变量中的文件夹以查找文件。 It's unlikely that your script is in one of the directories mentioned in %PATH% .您的脚本不太可能位于%PATH%中提到的目录之一中。

To see the contents of PATH, type ECHO %PATH% into a command prompt.要查看 PATH 的内容,请在命令提示符中键入ECHO %PATH% You can then move your script to one of the directories.然后,您可以将脚本移动到目录之一。

Alternatively, to temporarily (for the current CMD session) add a directory to PATH, run SET PATH=%PATH%;C:\path in your command prompt.或者,要临时(对于当前的 CMD 会话)将目录添加到 PATH,请在命令提示符下运行SET PATH=%PATH%;C:\path A permanent change in PATH requires use of the registry. PATH 的永久更改需要使用注册表。

I recommend you reconsider this approach however, as launching CMD then navigating to the script's location ( CD C:\path ) to then run the script is generally preferable to changing global variables.但是,我建议您重新考虑这种方法,因为启动 CMD 然后导航到脚本的位置( CD C:\path )然后运行脚本通常比更改全局变量更可取。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM