I am fairly new to VBScript. I have done some extensive research on what I am trying to accomplish and have even found examples of what to do, but cannot get it to work properly.
In my perfect world, I need to unzip all zipped files sent to a folder from a third-party vendor, import the unzipped file into a different folder then delete the zipped file.
The script below works properly for non-password protected zip files, but all files sent from the vendor have passwords. As seen in another post, the following lines which I have commented out should insert the password but do not. "...(pwd+myZipfile)
" and "...(pwd+extractTo)
".
Thank you in advanced for your help. Please suggest any code improvements or other methods to make this happen.
pathToZipFile = "P:\ZipFiles"
extractTo = "P:\UnZip"
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(pathToZipFile)
Set fc = f.Files
Dim myZipFile
Dim intOptions, objShell, objSource, objTarget
Dim pwd
pwd = "password"
For Each f1 in fc
On Error Resume Next
myZipFile = f1
' Create the required Shell objects
Set objShell = CreateObject( "Shell.Application" )
' Create a reference to the files and folders
'Set objSource = objShell.NameSpace(pwd+myZipFile).Items( )
Set objSource = objShell.NameSpace(myZipFile).Items( )
' Create a reference to the target folder
Set objTarget = objShell.NameSpace(pwd+extractTo)
Set objTarget = objShell.NameSpace(extractTo)
intOptions = 256
' UnZIP the file
objTarget.CopyHere objSource, intOptions
' Release the objects
Set objSource = Nothing
Set objTarget = Nothing
Set objShell = Nothing
'Delete File from "P:\ZipFiles" after unzipping
fso.DeleteFile f1, True
Next