我使用这个批处理来保持循环,直到我找到一个文件。有没有办法找到多个文件LookForFile= ("D:\File.txt" "D:\File1.txt" )
要求找到所有文件然后结束脚本..使用类似下面的批处理?
SET LookForFile="D:\File.txt"
:CheckForFile
IF EXIST %LookForFile% GOTO FoundIt
REM If we get here, the file is not found.
REM Wait 5 seconds and then recheck.
REM If no display is needed, comment/remove the timeout line.
TIMEOUT /T 5 >nul
GOTO CheckForFile
:FoundIt
REM If you are here the file is found
ECHO Found: %LookForFile%
任何建议都会很可爱。
答案 0 :(得分:1)
@echo off
setlocal enableextensions disabledelayedexpansion
:loop
rem Be optimistic
set "allFilesFound=1"
rem Now, check. If some file is not found clean variable
for %%a in (
"d:\file.txt" "d:\file1.txt"
) do if not exist "%%~a" set "allFilesFound="
rem If the variable is clean (it is not defined) there is
rem at least a missing file. Wait and check again
if not defined allFilesFound (
>nul 2>nul ping -n 6 localhost
goto :loop
)
rem Script continue here when all files are found
echo All files found