James Wilson
James Wilson

Reputation: 5150

Batch file if statement not working

I am trying to confgiure this batch file to copy over DLL's to the correct folder depending on weather it is a 64 bit machine or not.

Here is the batch file code:

c:
IF EXIST c:\Program Files (x86)\Latitude Software\bin\\.(
cd\Program Files (x86)\Latitude Software\bin
xcopy c:\collectdb\*.dll /y
)

c:
IF EXIST c:\Program Files\Latitude Software\bin\\.(
cd\Program Files\Latitude Software\bin
xcopy c:\collectdb\*.dll /y
)

PAUSE

It copies them correctly to the 64 bit folder on my machine. But when it checks to see if the c:\Program Files\Latitude Software\bin\. exists it seems to come back true because it tries to execute the code below again.

Just to be clear the c:\Program Files\Latitude Software\bin\. does not exist.

Are my IF statements incorrect?

Upvotes: 1

Views: 1755

Answers (2)

foxidrive
foxidrive

Reputation: 41287

The problem was the lack of quotes as mentioned in another answer, and also spaces before the parentheses became another issue.

Here is another method to solve your problem:

@echo off
IF EXIST "c:\Program Files (x86)\Latitude Software\bin\" (
    cd /d "c:\Program Files (x86)\Latitude Software\bin"
    xcopy "c:\collectdb\*.dll" . /y
  ) else (
    if exist "c:\Program Files\Latitude Software\bin\" (
       cd /d "c:\Program Files\Latitude Software\bin"
       xcopy "c:\collectdb\*.dll" . /y
    )
 )

Upvotes: 0

mihai_mandis
mihai_mandis

Reputation: 1658

Considering your original problem is to determine if the machine is 64 bit or not - I'd recommend to use %PROCESSOR_ARCHITECTURE% environment variable. I'm not sure if Windows creates "c:\Program Files (x86)" folder if there're no x86 programs installed. If "Program Files (x86)" folder does not exist by default - your method may fail.

    echo %PROCESSOR_ARCHITECTURE%
    if "%PROCESSOR_ARCHITECTURE%"=="x86" (
      echo Processor architecture is x86
      rem your code here
    ) else (
      echo Processor architecture is amd64
      if not exist "c:\Program Files (x86)" (
        mkdir "c:\Program Files (x86)"
        rem your code here
      )
    )

Upvotes: 1

Related Questions