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

Home Forums Scripting General Scripting if exists, [file] was unexpected at this time.

This topic contains 4 replies, has 4 voices, and was last updated by Avatar indrajit 1 year, 9 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • Avatar
    krayzie
    Member
    #155765

    hey guys

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

    @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 \fileserverNovelluninstallAcu.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

    [/CODE]

    but when i run the .bat i get the “c:Novellremoval.txt was unexpected at this time.”

    any help wil be muchly appreciated

    thanks[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 \fileserverNovelluninstallAcu.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

    [/CODE]

    but when i run the .bat i get the “c:Novellremoval.txt was unexpected at this time.”

    any help wil be muchly appreciated

    thanks

    tehcamel
    tehcamel
    Moderator
    #357930

    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

    Rems
    Rems
    Moderator
    #228037

    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

    tehcamel
    tehcamel
    Moderator
    #357937

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

    thanmk you for correcting me :)

    Avatar
    indrajit
    Member
    #391924

    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/47280217/was-unexpected-at-this-time-generated-from-batch-script-line-if-exist-file/47280406#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…

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

Register for this Petri Webinar!

Want to Make Your Backup Storage Unlimited & Ready for the Cloud? – Free Thurrott Premium Account with Webinar Registration!

Tuesday, August 27, 2019 @ 1:00 pm EDT

A Scale-Out Backup storage infrastructure is a must-have technology for your backups. In this webinar, join expert Rick Vanover for a look on what real-world problems are solved by the Scale-Out Backup Repository.

Register Now

Sponsored By