Well, this is not too difficult. There are a bunch of well-known batch tricks, such as mis-using ping to sleep (which saves you from having to integrate a non-standard tool) and we can then come up with the following:
@echo off
setlocal
set n=0
:start
ren test.g test.go
ping localhost -n 26>nul 2>&1
ren test.go test.g
set /a n+=25
if %n% LSS 300 goto start
endlocal
setlocal
and endlocal
will ensure that all environment variables we create and modify will remain only in scope of the batch file itself. The command
ping localhost -n 26 >nul 2>&1
will wait 25 seconds (because the first ping will be immediate and every subsequent one incurs a one-second delay) while throwing away all normal and error output (>nul 2>&1
).
Finally we are keeping track of how long we waited so far in the %n%
variable and only if n is still below 300 we continue looping. You might as well do it with a for loop, though:
@echo off
setlocal
set n=300
set /a k=n/25
for /l %%i in (1,1,%k%) do (
ren test.g test.go
ping localhost -n 26>nul 2>&1
ren test.go test.g
)
endlocal
which will first calculate how often it would need to loop and then just iterate the calculated number of times.