2013-12-16 87 views
1

我想批准這個批處理文件複製到DLL的正確的文件夾取決於天氣它是一個64位機器或不。批處理文件,如果語句不工作

這裏是批處理文件代碼:

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 

它複製他們正確地在我的機器上的64位文件夾。但是當它檢查是否c:\ Program Files \ Latitude Software \ bin \。存在它似乎回到真實,因爲它試圖再次執行下面的代碼。

只需清除c:\ Program Files \ Latitude Software \ bin \。不存在。

我的IF語句不正確嗎?

回答

1

考慮到你的原始問題是確定機器是否是64位 - 我建議使用%PROCESSOR_ARCHITECTURE%環境變量。 如果沒有安裝x86程序,我不確定Windows是否創建「c:\ Program Files(x86)」文件夾。 如果「Program Files(x86)」文件夾默認不存在 - 您的方法可能會失敗。

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 
    ) 
    ) 
+0

我的變量返回AMD64,是有很多的結果,這可能返回? –

+0

這個變量只有2個值(直到引入新的處理器架構:)):AMD64和X86 –

+0

我在答案中增加了一些代碼。 –

0

問題是在另一個答案中提到缺少引號,並且在括號之前的空格成爲另一個問題。

這裏是來解決問題的另一種方法:

@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 
    ) 
)