My Batch script is complaining that it can not find the path (not sure what path as its not too precise with explaining what is that its having problems with. The error message i get is:
C:/Users/Boss/AppData/Local/Temp/_.vbs(3, 1) Microsoft VBScript runtime error: Path not found
The whole idea of this script is to donwload tomcat (and not only) place it in specified directory, unzip and set it up. Now for some reason the UnZip method works perfectly fine for downloading and unziping Ant, but for Tomcat it does not. Below is the installAnt and installTomcat methods and UnZip method.
: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 function:
:: 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
Unfortunately i am not an expert with Batch files and i am having troubles figuring out why it works for Ant but not for Tomcat method.
Line 3 of that batch file:
:: @Author: Maciej Cygan
Given your:
>>%vbs% echo If NOT fso.FolderExists(%1) Then
>>%vbs% echo fso.CreateFolder(%1)
>>%vbs% echo End If
and this evidence:
>> p = "N:\ix"
>> If Not goFS.FolderExists(p) Then
>> goFS.CreateFolder p
>> End If
>>
Error Number: 76
Error Description: Path not found
I assume that your %1 argument holds a path that cannot be created because the prefix/parent path is invalid (no N: drive here). So (double) check the content of %1.
Added on second thought:
As you said:
Now for some reason the UnZip method works perfectly fine for downloading and unziping Ant, but for Tomcat it does not.
and wrote:
call :UnZipFile "%HOMEDRIVE\Apache\" "%HOMEDRIVE%\Apache\apache-tomcat-7.0.56.zip"
I further assume, that refering to HOMEDRIVE correctly - as in
call :UnZipFile "%HOMEDRIVE%\Apache\" "%HOMEDRIVE%\Apache\apache-tomcat-7.0.56.zip"
(mark the extra %), will solve your problem.