批处理文件 - VBScript运行时错误:找不到路径

时间:2016-11-17 11:56:54

标签: batch-file vbscript unzip

我的批处理脚本抱怨它无法找到路径(不确定哪条路径不太精确,解释它有什么问题。我得到的错误信息是:

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

这个脚本的整个想法是下载tomcat(而不仅仅是)将它放在指定的目录中,解压缩并设置它。现在由于某种原因,UnZip方法非常适合下载和解压缩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

1 个答案:

答案 0 :(得分: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的内容。

在第二个想法中添加:

正如你所说:

  

现在出于某种原因,UnZip方法非常适合   下载和解压缩Ant,但对于Tomcat,它没有。

并写道:

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"

(标记额外%),将解决您的问题。