Loop until file exists using windows batch command

女生的网名这么多〃 提交于 2021-02-18 05:14:42

问题


how can i convert following code into windows batch command?

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;
   }

}

回答1:


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

@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%


来源:https://stackoverflow.com/questions/27906705/loop-until-file-exists-using-windows-batch-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!