Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: how to check two conditions at a time using IF EXIST  (Read 8957 times)

0 Members and 1 Guest are viewing this topic.

krishnaanu

    Topic Starter


    Greenhorn

    how to check two conditions at a time using IF EXIST
    « on: December 11, 2009, 12:46:24 AM »
    Hi everybody, I am chaitanya, I want the syntax of a particular command. Let me explain my problem.

    I have two files located in two different directories. I want to check the existence of those two files. If those two files exist in the specified location "hi" should be echoed else the prompt should echo bye.

    It should look some thing like this:

    if exist c:\play.wav c:\lyrics\play.txt ( echo hi ) else ( echo bye ). I tried this but failed. I am able to check the existence if one file at a time. I want the command to be executed if those two files exist.

    Can anybody please help me?

    Thank you all in advance.

    Salmon Trout

    • Guest
    Re: how to check two conditions at a time using IF EXIST
    « Reply #1 on: December 11, 2009, 01:42:16 AM »
    Code: [Select]
    set flag=0
    if exist c:\play.wav set flag=1
    if exist c:\lyrics\play.txt set /a flag +=1
    if %flag% equ 2 ( echo hi ) else ( echo bye )

    krishnaanu

      Topic Starter


      Greenhorn

      Re: how to check two conditions at a time using IF EXIST
      « Reply #2 on: December 11, 2009, 03:14:38 AM »
      Thank you Salmon.

      Salmon Trout

      • Guest
      Re: how to check two conditions at a time using IF EXIST
      « Reply #3 on: December 11, 2009, 03:21:57 AM »
      Alternatives:

      Code: [Select]
      set bothexist=no
      if exist c:\play.wav if exist c:\lyrics\play.txt set bothexist=yes
      if "%bothexist%"=="yes" ( echo hi ) else ( echo bye )


      Code: [Select]
      set bothexist=no

      if exist c:\play.wav (
          if exist c:\lyrics\play.txt (
              set bothexist=yes
              )
          )

      if "%bothexist%"=="yes" (
          echo hi
          command(s) to execute if both exist
          ) else (
          echo bye
          command(s) to execute if both do not exist
          )