Help with my failing batch file

Discussion in 'Tech Talk' started by Tennessee Slim, Mar 8, 2007.

  1. Tennessee Slim

    Tennessee Slim Señor Member CLM

    Messages:
    4,413
    Likes Received:
    0
    Joined:
    Apr 14, 2004
    Location:
    Mucus City, USA
    I wrote a batch file for work yesterday that wouldn’t run and I can’t figure out why. I scrapped the first function and rewrote it and got it working but I’m still trying to figure out why the first version won’t run.

    I can run the entire batch file line-by-line from a command prompt and it runs perfectly. And I tried putting a “PAUSE” after every command but it apparently was puking so hard on the first line that it never took; I’d double-click on the batch file and the DOS window would flash and immediately close, not having executed a single step (if it had, it would have hit the “PAUSE” command and remained open, waiting for user input).

    It’s running against the local file structure on a W2K3SP1 server.
    Here’s the line:

    IF exist E:\Backup_DC\N01C\*Backup.bkf (

    I also tried it as…

    IF exist E:\Backup_DC\N01C\*Backup.bkf
    (


    …and…

    IF exist \\FQDN\E$\Backup_DC\N01C\*Backup.bkf (

    I replaced that clause with an “IF exist… …goto…” and it worked. I’ve used similar syntax hundreds of times before so I’m baffled as to why this one won't cooperate, and why it will execute from command line but won’t execute from batch file. I also tried is on my XPSP2 PC but it failed in exactly the same fashion.

    S’okay, what’s the goof I’m overlooking? There has to be one.
     
  2. David_G17

    David_G17 /\/\/\/\/\/\/\/

    Messages:
    2,046
    Likes Received:
    7
    Joined:
    Oct 7, 2002
    have you tried curly braces instead of parenthesis?

    "{" vs. "("

    Code:
    IF exists [i]filename[/i] {
    
    if you run it from within a command prompt, does it give any error messages?
     

  3. Tennessee Slim

    Tennessee Slim Señor Member CLM

    Messages:
    4,413
    Likes Received:
    0
    Joined:
    Apr 14, 2004
    Location:
    Mucus City, USA