Batch file help

TroganTrogan London, UK
edited March 2007 in Science & Tech
Guys, I need help/advice with two batch file commands. They are:
  1. If exist and go to
  2. If not exist and go to
I'm not sure if the "go to" parts are needed. What I need to do is to check if file "test.txt" exists at "C:\test\test.txt" - the file will exist. If it does not exist (if I delete "test.txt"), there needs to be an error message and the batch to close.

Can anyone help me or point me to a easy to understand batch file website?

Thanks! :)

Edit: Narrowed the problem in half. When the file is present, the batch gives a message that the file exists. When the file is deleted, the batch does not give an error message.

How do I get the batch to show an error message when the file is not present? I'm stuck! :(

Comments

  • jaredjared College Station, TX Icrontian
    edited March 2007
    I think something like this might be what you are talking about?
    if not exist test.txt goto MESSAGE
    echo The file test.txt exists in the current directory
    goto END
    :MESSAGE
    echo The file test.txt was not found.
    :END
    

    cheers :jared:
  • TroganTrogan London, UK
    edited March 2007
    Hi jared,

    What you gave works perfectly, but I'm still at a loss. The test.txt I mentioned above was just an example. This is what I have with all the files and folders involved...
    if exist c:\apps\av\license.txt goto present
    goto end
    :present
    echo File "license.txt" is PRESENT!
    
    if not exist c:\apps\av\license.txt goto message
    goto end
    :message
    echo File "license.txt" is not PRESENT!
    :end
    
    I can't get the batch to show File "license.txt" is not PRESENT!, when "license.txt" is not present. Can you see what the problem may be?

    Thanks for your help. :)
  • jaredjared College Station, TX Icrontian
    edited March 2007
    Ahhh ok I see what you are trying to do now! :cool:

    I think this should work.
    @echo off
    if exist c:\apps\av\license.txt (
        goto present
    ) ELSE (
        if not exist c:\apps\av\license.txt goto notpresent
    )
    
    :present
    echo File "license.txt" is PRESENT!
    goto end
    :notpresent
    echo File "license.txt" is not PRESENT!
    :end
    echo Done.
    

    cheers :jared:
  • TroganTrogan London, UK
    edited March 2007
    That works - w00t!

    Thank you! :thumbsup:
Sign In or Register to comment.