2016-11-17 139 views
0

我的批處理腳本抱怨說它找不到路徑(不確定它是什麼路徑,因爲它不太精確,解釋它有什麼問題。是:批處理文件 - VBScript運行時錯誤:找不到路徑

C:/Users/Boss/AppData/Local/Temp/_.vbs(3, 1) Microsoft VBScript runtime error: Path not found 

這個腳本的整個想法是donwload tomcat的(而不是隻)放置在指定的目錄,解壓並進行設置,現在由於某種原因,解壓方法工作完全正常下載和unziping Ant,但是對於Tomcat而言,它並不是。下面是installAnt和installTomcat方法以及UnZip方法。

:installAnt 
    ::----- ANT Section -----:: 

    :: Setup Apache Ant if Ant does not exist 
    md "%HOMEDRIVE%\Apache\apache-ant-1.9.7\" 2>nul 

    :: Set filename variable 
    SET "FILENAME=%~dp0\apache-ant-1.9.7-bin.zip" 

    :: Download ANT from mirror 
    bitsadmin.exe /transfer "Apache Ant Download" http://mirrors.ukfast.co.uk/sites/ftp.apache.org//ant/binaries/apache-ant-1.9.7-bin.zip "%FILENAME%" 

    :: Copy Apache Ant to C:\Apache 
    xcopy "%~dp0apache-ant-1.9.7-bin.zip" "%HOMEDRIVE%\Apache\." 

    :: Delete zip file from curent directory 
    del "%~dp0apache-ant-1.9.7-bin.zip" 

    :: Unzip Apache Ant to C:\Apache 
    call :UnZipFile "%HOMEDRIVE%\Apache\" "%HOMEDRIVE%\Apache\apache-ant-1.9.7-bin.zip" 

    :: Delete zip folder 
    del "%HOMEDRIVE%\Apache\apache-ant-1.9.7-bin.zip" 

    :: Set ANT_HOME path 
    set "ANT_HOME=%HOMEDRIVE%\Apache\apache-ant-1.9.7" 
    setx ANT_HOME "%HOMEDRIVE%\Apache\apache-ant-1.9.7" /m 

    :: Add ANT to path 
    set "path=%PATH%;%ant_home%\bin" 
    setx path "%PATH%" /m 

    goto checkIvy 

:installTomcat 
    ::----- Tomcat Section -----:: 
    echo Installing tomcat 
    :: Setup Apache Tomcat if Tomcat does not exist 
    md "%HOMEDRIVE%\Apache\apache-tomcat-7.0.56\" 2>nul 

    :: Set filename variable 
    SET "FILENAME=%~dp0\apache-tomcat-7.0.56.zip" 

    :: Download Tomcat from mirror 
    bitsadmin.exe /transfer "Apache Tomcat Donwload" http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.56/bin/apache-tomcat-7.0.56.zip "%FILENAME%" 


    :: Copy Apache Tomcat to C:\Apache 
    xcopy "%~dp0apache-tomcat-7.0.56.zip" "%HOMEDRIVE%\Apache\." 

    :: Delete zip file from curent direcotry 
    del "%~dp0apache-tomcat-7.0.56.zip" 

    :: Unzip Apache Tomcat to C:\Apache 
    call :UnZipFile "%HOMEDRIVE\Apache\" "%HOMEDRIVE%\Apache\apache-tomcat-7.0.56.zip" 

    pause 

    rem :: Delete zip folder 
    rem del "%HOMEDRIVE%\Apache\apache-tomcat-7.0.56.zip" 

    rem :: Set TOMCAT_HOME 
    rem set "TOMCAT_HOME=%HOMEDRIVE%\Apache\apache-tomcat-7.0.56" 
    rem setx TOMCAT_HOME "%HOMEDRIVE%\Apache\apache-tomcat-7.0.56" /m 

    rem :: Add TOMCAT to path 
    rem set "path=%PaTH%;%tomcat_home%\bin" 
    rem setx path "%PATH%" /m 

解壓縮功能:

:: Unzip file 
:UnZipFile <ExtractTo> <newzipfile> 
set vbs="%temp%\_.vbs" 
if exist %vbs% del /f /q %vbs% 
>%vbs% echo Set fso = CreateObject("Scripting.FileSystemObject") 
>>%vbs% echo If NOT fso.FolderExists(%1) Then 
>>%vbs% echo fso.CreateFolder(%1) 
>>%vbs% echo End If 
>>%vbs% echo set objShell = CreateObject("Shell.Application") 
>>%vbs% echo set FilesInZip=objShell.NameSpace(%2).items 
>>%vbs% echo objShell.NameSpace(%1).CopyHere(FilesInZip) 
>>%vbs% echo Set fso = Nothing 
>>%vbs% echo Set objShell = Nothing 
cscript //nologo %vbs% 
if exist %vbs% del /f /q %vbs% 
goto :eof 

可惜我不是用批處理文件的專家,我有麻煩弄清楚爲什麼它的工作原理爲Ant而不是Tomcat的方法。

該批處理文件的第3行:

:: @Author: Maciej Cygan 
+0

錯誤來自生成的VBScript,而不是來自批處理文件。該文件的第3行是什麼樣的? –

+0

@AnsgarWiechers它只是一個評論真正的更新 –

+0

生成的VBScript的第3行,** NOT **批處理文件。 –

回答

1

鑑於你:

>>%vbs% echo If NOT fso.FolderExists(%1) Then 
>>%vbs% echo fso.CreateFolder(%1) 
>>%vbs% echo End If 

和這方面的證據:

>> p = "N:\ix" 
>> If Not goFS.FolderExists(p) Then 
>> goFS.CreateFolder p 
>> End If 
>> 
Error Number:  76 
Error Description: Path not found 

我假設你的%1論點成立一個路徑無法創建,因爲前綴/父路徑無效(這裏沒有N:驅動器)。因此(雙)檢查%1的內容。

添加於第二個想法:

至於你說:

Now for some reason the UnZip method works perfectly fine for downloading and unziping Ant, but for Tomcat it does not.

,並寫道:

call :UnZipFile "%HOMEDRIVE\Apache\" "%HOMEDRIVE%\Apache\apache-tomcat-7.0.56.zip" 

我進一步假設,那指的正確HOMEDRIVE - 在

call :UnZipFile "%HOMEDRIVE%\Apache\" "%HOMEDRIVE%\Apache\apache-tomcat-7.0.56.zip" 

(標出額外的%),將解決您的問題。

+0

哦,上帝......愛他們的錯別字,幾個小時在主演血腥的事情,並沒有注意到@MaciejCygan –

+0

,你不應該盯着它幾個小時。你所要做的就是正確排除故障。如果你看你的腳本逐行執行,你會發現變量%homedrive%從未擴展到它的值。您甚至在該行後面的代碼中停頓了一下。它正盯着你。 – Squashman

+0

@Squashman是的,但有時最容易找到的東西最難# –