更改路径后批处理超时不起作用?

Dat*_*cho 1 cmd batch-file

我是 cmd 的新手。我创建了一个文件来创建文件夹和子文件夹。我放了一些timeout。第一个timeout正在工作,但其他超时不起作用不知道为什么。是不是因为改了path. 我已在 CMD 中逐行检查。在 CMD 中它工作正常。

输入:

timeout /t 5

@echo off
set path=C:\Users\bruce\Documents\Project-Gallary
cd %path%
@echo "Welcome master Bruce !"
@echo "Recommended Project Folder Name: G01-Global-Report/C01-Compliance"
echo %PATH%
timeout /t 10
@echo " *** Try not the put space in Folder Name"
set /p ProjectName="What is the project name? "
Run Code Online (Sandbox Code Playgroud)

输出:

C:\Users\bruce\Desktop>timeout /t 5

Waiting for 0 seconds, press a key to continue ...
"Recommended Project Folder Name: G01-Global-Report/C01-Compliance"
C:\Users\bruce\Documents\Project-Gallary
'timeout' is not recognized as an internal or external command,
operable program or batch file.
" *** Try not the put space in Folder Name"
What is the project name?
Run Code Online (Sandbox Code Playgroud)

Ger*_*ard 5

大错误,您正在更改系统变量 PATH

系统变量路径列出了可执行文件的所有路径,您通过设置更改了它set path=C:\Users\bruce\Documents\Project-Gallary,现在不再找到其他 cmd。

试试这个版本,首先关闭所有cmd.exe窗口以清除所有set命令。

@echo off
set "mypath=C:\Users\bruce\Documents\Project-Gallary"
cd %mypath%
@echo "Welcome master Bruce !"
@echo "Recommended Project Folder Name: G01-Global-Report/C01-Compliance"
echo %PATH%
timeout /t 10
@echo " *** Try not the put space in Folder Name"
set /p ProjectName="What is the project name? "
Run Code Online (Sandbox Code Playgroud)

编辑

基于@npocmaka 的评论。如果您确实想将路径添加到系统路径变量,则只需将该set path行替换为:

set "PATH=%PATH%;C:\Users\bruce\Documents\Project-Gallary"
Run Code Online (Sandbox Code Playgroud)