使用 Windows 批处理命令循环直到文件存在 [英] Loop until file exists using windows batch command

查看:33
本文介绍了使用 Windows 批处理命令循环直到文件存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

how can i convert following code into windows batch command?

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

Here is a perl script which is searching for a file in a while loop, if found it Exits.

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

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

}

推荐答案

这是一个相当直接的翻译.代码应该一目了然:

This is a fairly straight-forward translation. The code should be pretty self-explanatory:

@ECHO OFF
SET LookForFile="C:PathToFile.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%

这篇关于使用 Windows 批处理命令循环直到文件存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆