加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

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

发布时间:2020-12-13 22:31:02 所属栏目:Windows 来源:网络整理
导读:如何将以下代码转换为 Windows批处理命令? 这是一个perl脚本,它在while循环中搜索文件,如果发现它退出. use strict;use warnings;my $filename = 'something.txt'; while (1) {if (-e $filename) {print "File Exists!"; exit; }} 解决方法 这是一个相当直
如何将以下代码转换为 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: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%

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读