0

I have made ​​a batch script to perform the following tasks : if the file abc.laccdb still in the update folder , show a message : wait a minute.... if abc.laccdb file is not in the 'update' folder , show a message : updating data successfully..

My Batch script is :

@ECHO OFF
start update_data.vbs
:check
FOR %%F IN (update\abc.laccdb) DO (
echo wait a minute...
goto :check
)
echo updating data successfully
pause

with the script above , the message "wait a minute ... " continuously displayed in command prompt window, even though abc.laccdb file has not in the Update folder. properly if the abc.laccdb file is not there in the Update folder, the bacth application run the next line (echo updating data successfully). please correct my script. thank you :)

2 Answers 2

2

A for command with a wildcard will enumerate the files matching the wildcard, but without a wildcard, it will not ensure that the file exists, so the code in the do clause will always be executed whether the file exists or not.

Use

@ECHO OFF
    start update_data.vbs

:check
    ping -n 3 localhost >nul 2>nul 
    if exist "update\abc.laccdb" (
        echo wait a minute...
        goto :check
    )
    echo updating data successfully
    pause    

It is not always a good idea to have a waiting loop without some kind of wait. The ping has been included to generate a 2 seconds pause between loops to reduce the cpu usage.

Sign up to request clarification or add additional context in comments.

3 Comments

thank you for your advice, but stay not work. the message "wait a minute ... " continuously displayed in command prompt window
@flyingbird013, as the paths to the folder/file are relative to the current active directory (not the batch folder), please ensure the folder/file if the check is the correct one. The wait a minute... will display for each loop until the flag file is deleted. If you don't want that repetition, move the echo before the :check label
good news .. after I changed the line ping -n 3 localhost >nul 2>nul into ping -n 6 localhost >nul 5>nul , my problem is solved. thankyou very much
1

Using MC ND's answer:

@ECHO OFF
    echo wait a minute...
    start update_data.vbs
    ping -n 5 localhost >nul 2>nul 
:check
    if exist "update\abc.laccdb" (
        ping -n 3 localhost >nul 2>nul 
        goto :check
    )
    echo updating data successfully
    pause

Display echo wait a minute... message in advance...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.