如果不存在则退出+ cmd

Seb*_*ian 9 cmd dos

我尝试在.cmd文件中创建一个循环.

如果test.txt不存在,那么我将终止cmd进程.

@echo off
if not exists test.txt goto exit
Run Code Online (Sandbox Code Playgroud)

但是这段代码不起作用,我不知道如何每2秒做一次循环.

感谢帮助.

tan*_*ius 15

该命令被调用exist,不存在:

if not exist test.txt goto :exit
echo file exists
:exit
Run Code Online (Sandbox Code Playgroud)

关于你的循环:
我不是100%肯定,但我认为在Windows中没有睡眠等待命令.你可以谷歌睡觉找到一些免费软件.另一种可能是使用ping:

ping localhost -n 3 >NUL
Run Code Online (Sandbox Code Playgroud)

编辑:
Windows Server 2003的资源工具包工具包含睡眠.
有关更多信息,请参见此处