Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loop until file exists using windows batch command

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

}
like image 754
Mihir Avatar asked Jan 12 '15 16:01

Mihir


1 Answers

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%
like image 98
Jason Faulkner Avatar answered Nov 15 '22 23:11

Jason Faulkner