I am automating a file download thorough CuteFTP using VBScript. At the end of the VBScript I am calling a batch file that will use 7zip's CLI to expand the zip file.
The batch file and the 7zip executable are stored on Server1 (nt950id3). The expansion takes place on Server2 (nt950a1). Due to corporate restrictions, this cannot be changed. Since the VBS is working, I have omitted its code. This is the batch command-
"\\nt950id3\c$\apps\CFI\7zip\7za.exe" e -y "\\nt950a1\filexfr$\Spectrum\File.zip" -o"\\nt950a1\filexfr$\Spectrum"
Expansion is accomplished awkwardly because 7zip will extract to the CWD of the batch file, as opposed to the directory the zip file is in unless I specify the -o
switch.
When I double-click the batch file or run it via a scheduled task, it works just peachy. When VBScript calls the batch file, it fails stating UNC paths are not supported - I did not know there would be a difference. PUSHD
and POPD
should fix this.
Further research through this post on CLI Crash Course lead me to use PUSHD
on each directory and set them as variables-
SET UZEXE=PUSHD "\\nt950id3\c$\apps\CFI\7zip\7za.exe"
SET ZSRC=PUSHD "\\nt950a1\filexfr$\Spectrum\File.zip"
SET ZEDST=PUSHD "\\nt950a1\filexfr$\Spectrum"
At the bottom of the code I use 'POPD' three times (also attempted at the end of each line) and despite having this very simple SO post on setting paths I am unable to make this work. I also attempted this without PUSHD
-
SET UZEXE="\\nt950id3\c$\apps\CFI\7zip\7za.exe"
This also failed stating UNC paths are not supported.
Could the community kindly explain my errors and point me towards an example of how I can accomplish running a command using multiple, separate PUSHD
/POPD
directories?
Following Bill's guidance, I used only VBS - no calls to batch - for my issue. I was not aware this was so easily possible and will endeavor to do better research going forward. The working code - with stand-in UNC paths - is as follows:
Set wshShell = CreateObject("wscript.shell")
wshShell.Run"""\\server1\path\7z.exe"" e -y ""\\server1\path\srcfile.zip"" -o\\server2\path\unzipdest", 0, True
At first, the executing code stated it could not find the file. This turned out to be an issue with white space in the file paths. After using this Google groups topic to learn to properly place the quotes, it is now working within the CuteFTP script with no errors.