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

Author Topic: HELP ME PLEASE!!!...IF command  (Read 3351 times)

0 Members and 1 Guest are viewing this topic.

Xeneinxe14

    Topic Starter


    Greenhorn

    HELP ME PLEASE!!!...IF command
    « on: May 21, 2009, 10:40:17 PM »
    I don`t know what`s wrong...
    -----------------------------------------------------------
    IF EXIST file.ext (GOTO yes) ELSE (GOTO no)
    :yes
    ...
    Exit
    :no
    ...
    Exit
    -----------------------------------------------------------

    or the other way...
    -------------------------------------------
    IF EXIST file.ext GOTO yes
    IF NOT EXIST file.ext GOTO no
    :yes
    ...
    Exit
    :no
    ...
    Exit
    -------------------------------------------

    Somebody can help me whit these batch`s files...

     :P sorry for my english!

    BatchFileBasics



      Hopeful

      Thanked: 18
      Re: HELP ME PLEASE!!!...IF command
      « Reply #1 on: May 21, 2009, 10:45:27 PM »
      I don`t know what`s wrong...
      -----------------------------------------------------------
      IF EXIST file.ext (GOTO yes) ELSE (GOTO no)
      :yes
      ...
      Exit
      :no
      ...
      Exit
      -----------------------------------------------------------

      or the other way...
      -------------------------------------------
      IF EXIST file.ext GOTO yes
      IF NOT EXIST file.ext GOTO no
      :yes
      ...
      Exit
      :no
      ...
      Exit
      -------------------------------------------

      Somebody can help me whit these batch`s files...

       :P sorry for my english!

      well lets look at:
      Code: [Select]
      IF EXIST file.ext GOTO yes
      IF NOT EXIST file.ext GOTO no
      :yes
      ...
      Exit
      :no
      ...
      Exit

      You don't need
      Code: [Select]
      IF NOT EXIST file.ext GOTO no
      since theres no other option
      so your looking at
      Code: [Select]
      IF EXIST file.ext GOTO yes
      goto no
      so if it exists, goto yes, if it doesn't it will continue the script and goto no

      ALSO.
      you might want to add in the directory of the file
      When the power of love overcomes the love of power the world will know peace - Jimi Hendrix.

      Xeneinxe14

        Topic Starter


        Greenhorn

        Re: HELP ME PLEASE!!!...IF command
        « Reply #2 on: May 21, 2009, 10:53:13 PM »
        I try it but the IF command don`t work with GOTO

        BatchFileBasics



          Hopeful

          Thanked: 18
          Re: HELP ME PLEASE!!!...IF command
          « Reply #3 on: May 21, 2009, 10:56:27 PM »
          are you sure your doing it like this?
          Code: [Select]
          if exist c:\windows\myfile.txt goto yes
          goto no

          well try this code out, except replace myfile.txt with the name of your file
          Code: [Select]
          @echo off
          if exist c:\windows\myfile.txt goto yes
          goto no

          :yes
          echo Worked
          pause
          exit

          :no
          echo didn't work
          pause
          exit

          When the power of love overcomes the love of power the world will know peace - Jimi Hendrix.

          Xeneinxe14

            Topic Starter


            Greenhorn

            Re: HELP ME PLEASE!!!...IF command
            « Reply #4 on: May 21, 2009, 11:05:24 PM »
            The original .bat be...
            -----------------------------------------------
            IF EXIST autorun.inf GOTO yes
            goto no
            :yes
            ren ....
            del...
            exit
            :no
            echo...
            set /p...
            ...etc...
            exit
            ---------------------------------------------------
            but the shell show me something like this
            "The command`s syntax is incorrect"

            BatchFileBasics



              Hopeful

              Thanked: 18
              Re: HELP ME PLEASE!!!...IF command
              « Reply #5 on: May 21, 2009, 11:10:17 PM »
              thats interesting.

              well lets see the full error:

              open up command prompt
              type the full path and name of your batch
              c:\path of file\file.bat

              and press enter.

              and it should say the error then resume to command prompt
              When the power of love overcomes the love of power the world will know peace - Jimi Hendrix.

              Xeneinxe14

                Topic Starter


                Greenhorn

                Re: HELP ME PLEASE!!!...IF command
                « Reply #6 on: May 21, 2009, 11:19:00 PM »
                I don`t understand why appear the message "The syntax of the command is incorrect"...I follow you step to step....fu___ batch >:(

                BatchFileBasics



                  Hopeful

                  Thanked: 18
                  Re: HELP ME PLEASE!!!...IF command
                  « Reply #7 on: May 21, 2009, 11:40:08 PM »
                  well there goes my ideas.
                  the if syntax shouldn't have any problems with exist.

                  so if anyone else wants to try and help. please
                  When the power of love overcomes the love of power the world will know peace - Jimi Hendrix.

                  Dias de verano

                  • Guest
                  Re: HELP ME PLEASE!!!...IF command
                  « Reply #8 on: May 22, 2009, 12:54:57 AM »
                  (1) If the file is not in the same folder as the batch file you need to use the full path.

                  (2) If the file name and/or path has one or more spaces you need quote marks before and after it. They do not do any harm if there are no spaces.

                  (3) Contents of folder:

                  Code: [Select]
                  S:\Test\Batch\ifexist>dir
                   Volume in drive S is USBHD
                   Volume Serial Number is 2C51-AA7F

                   Directory of S:\Test\Batch\ifexist

                  22/05/2009  07:40    <DIR>          ..
                  22/05/2009  07:40    <DIR>          .
                  22/05/2009  07:40                 7 test.txt
                  22/05/2009  07:43               137 test.bat
                                 2 File(s)            144 bytes

                  (4) test.bat:

                  Code: [Select]
                  @echo off
                  if exist "test.txt" (goto yes) else (goto no)
                  :yes
                  echo file exists
                  goto end
                  :no
                  echo file does not exist
                  :end
                  pause

                  (5) Output on screen:

                  Code: [Select]
                  S:\Test\Batch\ifexist>test.bat
                  file exists
                  Press any key to continue . . .

                  (6) I edited test.bat: I changed if exist test.txt to if exist test1.txt (which does not exist)...

                  Code: [Select]
                  S:\Test\Batch\ifexist>test.bat
                  file does not exist
                  Press any key to continue . . .




                  Dusty



                    Egghead

                  • I could if she would, but she won't so I don't.
                  • Thanked: 75
                  • Experience: Beginner
                  • OS: Windows XP
                  Re: HELP ME PLEASE!!!...IF command
                  « Reply #9 on: May 22, 2009, 02:09:25 AM »
                  Can the OP show which command line is causing the error or is it just assumed that it's the If exist command line?
                  One good deed is worth more than a year of good intentions.

                  Xeneinxe14

                    Topic Starter


                    Greenhorn

                    Re: HELP ME PLEASE!!!...IF command
                    « Reply #10 on: May 22, 2009, 09:28:36 AM »
                    OK tanks everybody...but, for example I have in a directory named "Test" the next files: autorun .inf, autorunH.inf and the batch.
                    The batch cotains the next commands:
                    -----------------------------------------------------------------------------------
                    @echo off
                    IF exist "Autorun.inf" (GOTO yes) ELSE (GOTO no)
                    :yes
                    ren %USERPROFILE%\desktop\test\Autorun.inf Autorun1.inf
                    ren %USERPROFILE%\desktop\test\AutorunH.inf Autorun.inf
                    pause
                    Exit
                    :no
                    ren %USERPROFILE%\desktop\test\AutorunH.inf Autorun.inf
                    pause
                    Exit
                    ------------------------------------------------------------------------------------
                    but the batch file doesn`t works cause appear the same message ervery time "The syntax of the command is incorrect"...
                    What is it OP?

                    Dias de verano

                    • Guest
                    Re: HELP ME PLEASE!!!...IF command
                    « Reply #11 on: May 22, 2009, 10:55:01 AM »
                    1. You didn't take any notice of what I wrote about paths and filenames with spaces in them.

                    2. The OP is you. Original Poster.