file - 使用 Windows 批处理命令循环直到文件存在

标签 file batch-file while-loop command line

如何将以下代码转换为 Windows 批处理命令?

这是一个 perl 脚本,它在 while 循环中搜索文件,如果找到则退出。

use strict;
use warnings;
my $filename = 'something.txt'; 
while (1) {

if (-e $filename) {
print "File Exists!";
   exit;
   }

}

最佳答案

这是一个相当直接的翻译。代码应该是不言自明的:

@ECHO OFF
SET LookForFile="C:\Path\To\File.txt"

:CheckForFile
IF EXIST %LookForFile% GOTO FoundIt

REM If we get here, the file is not found.

REM Wait 60 seconds and then recheck.
REM If no delay is needed, comment/remove the timeout line.
TIMEOUT /T 60 >nul

GOTO CheckForFile


:FoundIt
ECHO Found: %LookForFile%

关于file - 使用 Windows 批处理命令循环直到文件存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27906705/

相关文章:

windows - 如何将 .bat 文件中的变量导入到 PowerShell 脚本中?

python - 使用!=获得python while语句

java - 在 java 中使用 while 循环时出现 Unreachable 语句错误

Javascript while 或 for 循环更改字符串直到满足条件

ios - 保证 iOS 何时写入 Documents 目录中的文件?

c++ - 使用 fopen 打开文件,在 Windows 上给定绝对路径

python - 如果 Python 程序被杀死,自动重启它

batch-file - 批处理文件查找Exe的路径并运行程序

C++ 解析为自定义语言解释器

c++ - 文件输入输出