

InterviewSolution
1. |
Solve : VBScript to Unzip Issues? |
Answer» I'm not very proficient in VBS, infact, I took this script from another thread on this FORUM, I'm just trying to implement it to my needs. Why does the batch file remove the .zip extension, and the vbs script add it back again?So if I add .zip it won't look for .zip.zip files, and if I don't then it will automatically add .zip to the END. But anyway, can you help?The problem is that the VBScript cannot see the environment variables from the batch file. An alternative is to pass the variables on the CScript command line where the VBScript can see them. Code: [Select]If WScript.Arguments.Unnamed.Count <> 2 Then WScript.Echo "Invalid arguments...Job Terminated" WScript.Quit End If strZipFile = WScript.Arguments.Unnamed(1) & "\" & WScript.Arguments.Unnamed(0) & ".zip" outFolder = WScript.Arguments.Unnamed(1) Set objShell = CreateObject( "Shell.Application" ) Set objSource = objShell.NameSpace(strZipFile).Items() Set objTarget = objShell.NameSpace(outFolder) intOptions = 256 objTarget.CopyHere objSource, intOptions Code: [Select]@echo off set file=%1 set file=%file:.zip=% cscript //nologo vb.vbs "%file%" "%cd%" pause Run your batch file like you always do. Good luck. When I post on the forum, I very rarely put in error checking routines. FEEL free to add your own.Thanks, but can you tell me how to add error-checking routines? I added an if exist test to the batch file, to make sure the .zip exists.Quote I added an if exist test to the batch file, to make sure the .zip exists. That's all you really need. Not sure if the CopyHere method will create a new folder if it doesn't exist, but you can test that yourself. |
|