Announcement

Collapse
No announcement yet.

if exists, [file] was unexpected at this time.

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • if exists, [file] was unexpected at this time.

    hey guys

    im trying to run a command to uninstall some novell products apon logon

    Code:
    @echo off
    REM REMOVE NOVELL PRODUCTS
    
    if exists c:\Novellremoval.txt goto :exit else goto :uninstall
    
    :uninstall
    :Run Windows XP specific commands here.
    echo Windows XP
    
    REM NCL
    CALL \\fileserver\Novelluninstall\Acu.exe
    
    REMzen works
    
    MsiExec.exe /x{7878B1D4-B2CB-4EA8-9A0A-7E0575D23B96} /quiet
    
    echo Novell client removed on %date% on %time% by %username% > c:\Novellremoval.txt
    
    goto :exit
    
    :exit
    but when i run the .bat i get the "c:\Novellremoval.txt was unexpected at this time."

    any help wil be muchly appreciated

    thanks

  • #2
    Re: if exists, [file] was unexpected at this time.

    try this:


    if exist C:\novell.txt (
    goto :exit )
    else
    (goto :uninstall )


    ref:
    http://www.computerhope.com/if.htm
    Please do show your appreciation to those who assist you by leaving Rep Point https://www.petri.com/forums/core/im.../icon_beer.gif

    Comment


    • #3
      Re: if exists, [file] was unexpected at this time.

      In your batch "IF EXISTS" should be "IF EXIST". And, when there is an ELSE - the command (or commands) to carry out if the condition is met should be (grouped) between round brackets.

      if exist "c:\Novellremoval.txt" (goto :end) else goto :uninstall

      If you like you can add a line break after the opening_bracket.

      A correction to tehcamel's sample, the ELSE clause should be part of the IF statement,

      if exist "C:\novell.txt" (
      goto :end
      ) else (
      goto :uninstall)



      Just FYI, here is also an difference approach (not that this would be a better one though),
      dir /b "c:\Novellremoval.txt" &&goto :end ||goto :uninstall


      /Rems

      This posting is provided "AS IS" with no warranties, and confers no rights.

      __________________

      ** Remember to give credit where credit's due **
      and leave Reputation Points for meaningful posts

      Comment


      • #4
        Re: if exists, [file] was unexpected at this time.

        thanmk you for correcting me
        Please do show your appreciation to those who assist you by leaving Rep Point https://www.petri.com/forums/core/im.../icon_beer.gif

        Comment


        • #5
          I had a very similar problem and code construct that was causing me a lot of pain to resolve. My error message was **". was unexpected at this time"**...

          It took me a couple long days to figure out another similar consideration due to this problem... Please take a look a the following problem and subsequent solution here: https://stackoverflow.com/questions/...80406#47280406

          It also contains a very good detailed reply by user magoo...

          The solution was simply the treatment of '(' and ')' on ECHO lines inside an IF statement block.

          The point is, do consider treatment of special characters as a possible source of a problem when troubleshooting IF (and possibly FOR) statements.

          HTH someone...

          Comment

          Working...
          X