I am try to loop all the source file in array and make sure it is exits in the folder with the file path I have set, below is my code
@echo OFF
setlocal EnableExtensions EnableDelayedExpansion
set "string_list=A.txt B.txt C.txt D.txt"
set count=0
For %%j in (%string_list%) Do Set /A count+=1
rem echo.Total count: %count%
set current_count=0
REM for %%s in (%string_list%) do (
for %%s in (%string_list%) do (
set "var=C:\Users\ABC\Desktop\TESTING\%%s"
rem echo "!var!"
:START
if not exist "!var!" GOTO WAIT
GOTO COPY
:WAIT
timeout 5
ECHO "MISSING !var!, WAITING SOURCE FILE TO LOAD IN"
GOTO START
:COPY
ECHO "!var! FILES IS AVAIALBLE"
set /A current_count+=1
if /I %current_count%==%count% (
echo "ALL THE FILE IS IS AVAILABLE"
) else (
echo "CONTINUE CHECK FOR OTHER FILE"
)
)
rem echo %current_count%
pause
It will exit the loop once it found the first file. The code is to check and make sure all the files are in the folder, if one of the file is not there then continue loop until the file is there.
I am not sure can the function add in the FOR loop.
I'm expecting this:
C:\Users\ABC\Desktop\TESTING\A.txt FILES IS AVAILABLE<- A.txt is in the folderWaiting for 0 seconds, press a key to continue ...
But I'm getting this:
MISSING C:\Users\ABC\Desktop\TESTING\B.txt, WAITING SOURCE FILE TO LOAD IN <- B.txt is not in the folder for the first time.
C:\Users\ABC\Desktop\TESTING\B.txt FILES IS AVAIALBLE <- B.txt is in the folder for the second loop
C:\Users\ABC\Desktop\TESTING\C.txt FILES IS AVAIALBLE <- C.txt is in the folder
C:\Users\ABC\Desktop\TESTING\D.txt FILES IS AVAIALBLE <- D.txt is in the folder
The loop should only exit if all the files are in the folder, or else it will continue loop.