danwinson
asked on
vbscript: How can you create a zipped folder?
I need to compress event log files using a script, but don't want to use NTFS compression (CIM_DataFile .Compress method).
How can I script the use of the built in 'compress folder' (zipfldr.dll) feature of Windows Server 2003?
How can I script the use of the built in 'compress folder' (zipfldr.dll) feature of Windows Server 2003?
Sorry, missed a bit:
>> Otherwise, you should download a command-line archiver, such as 7-Zip, and use that.
Otherwise, you should download a command-line archiver, such as 7-Zip, and use a Shell object to run that.
>> Otherwise, you should download a command-line archiver, such as 7-Zip, and use that.
Otherwise, you should download a command-line archiver, such as 7-Zip, and use a Shell object to run that.
there are lot of ipp & unzip wares available for free download...DOS shell executables
U can also use PKzip and PkUnzip..u can also find some example codings for that..
One of the nice tool i used in my previous applications..try n tell me
cheers
U can also use PKzip and PkUnzip..u can also find some example codings for that..
One of the nice tool i used in my previous applications..try n tell me
cheers
ASKER
While the comments received were to an extent helpful, I do not have the option of installing third party software so they don't fix my problem (or answer the question). Thanks everyone for your help though. Can I please have the points refunded.
From http://www.mvps.org/emorcillo/vb6/shell/xpzip.shtml:
"There's no API in Windows to work with .zip files but the compressed folder file extension can be used from VB to
compress and decompress files in .zip files."
This suggests that you may be able to simply make a folder (with the FSO) called something.zip and it will make the zip file.
To test this, try:
Dim oFSO, oFile, oFolder
Set oFSO = CreateObject("Scripting.Fi leSystemOb ject")
Set oFolder = oFSO.CreateFolder("x:\mydi r\myzipfil e.zip")
Set oFile = oFSO.GetFile("x:\mydir\myf iletoadd")
oFile.Copy oFolder.Path
HTH
J.
"There's no API in Windows to work with .zip files but the compressed folder file extension can be used from VB to
compress and decompress files in .zip files."
This suggests that you may be able to simply make a folder (with the FSO) called something.zip and it will make the zip file.
To test this, try:
Dim oFSO, oFile, oFolder
Set oFSO = CreateObject("Scripting.Fi
Set oFolder = oFSO.CreateFolder("x:\mydi
Set oFile = oFSO.GetFile("x:\mydir\myf
oFile.Copy oFolder.Path
HTH
J.
ASKER
I tried your code but it seems to just create a folder called myzipfile.zip, it doesn't create a zip file. Please let me know if I might be doing something wrong.
I checked out the link to mvps, it does provide info on how to do this using a VB6 class, but I don't know if this code can be scripted, I can't load any new .exe files onto the server in question, only vbs files. What sort of portability is there between VB6 code and vbscript?
I checked out the link to mvps, it does provide info on how to do this using a VB6 class, but I don't know if this code can be scripted, I can't load any new .exe files onto the server in question, only vbs files. What sort of portability is there between VB6 code and vbscript?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
the above answer didn't exactly answer my question, but the effort put in by jimbobmcgee, the clarity of the response and the fact that it effectively rules out any other correct answer to my response deserves the points.
There is a solution using VBScript only:
Const FOF_CREATEPROGRESSDLG = &H0&
With CreateObject("Shell.Applic ation")
For each Fldr in SrcFldrs
'Copy the files to the compressed folder
.NameSpace(ZipFile).CopyHe re .NameSpace(Fldr).Items, FOF_CREATEPROGRESSDLG
iFiles = iFiles + .NameSpace(Fldr).Items.Cou nt
'Keep script waiting until Compressing is done
On Error Resume Next
Do Until .NameSpace(ZipFile).Items. Count = iFiles
wScript.Sleep 1000
Loop
On Error GoTo 0
Next
End With
Const FOF_CREATEPROGRESSDLG = &H0&
With CreateObject("Shell.Applic
For each Fldr in SrcFldrs
'Copy the files to the compressed folder
.NameSpace(ZipFile).CopyHe
iFiles = iFiles + .NameSpace(Fldr).Items.Cou
'Keep script waiting until Compressing is done
On Error Resume Next
Do Until .NameSpace(ZipFile).Items.
wScript.Sleep 1000
Loop
On Error GoTo 0
Next
End With
I can confirm that the above approach works, with one caveat; you must create the zip file first. As such, the following slight alteration would apply.
Const FOF_CREATEPROGRESSDLG = &H0&
Dim ZipFile : ZipFile = "C:\vbscripted.zip"
Dim SrcFldrs : SrcFldrs = Array("D:\Documents and Settings\jimbobmcgee\My Documents")
With CreateObject("Scripting.Fi leSystemOb ject")
.OpenTextFile ZipFile, 2, true
End With
With CreateObject("Shell.Applic ation")
For each Fldr in SrcFldrs
'Copy the files to the compressed folder
.NameSpace(ZipFile).CopyHe re .NameSpace(Fldr).Items, FOF_CREATEPROGRESSDLG
iFiles = iFiles + .NameSpace(Fldr).Items.Cou nt
'Keep script waiting until Compressing is done
On Error Resume Next
Do Until .NameSpace(ZipFile).Items. Count = iFiles
wScript.Sleep 1000
Loop
On Error GoTo 0
Next
End With
Shame its 5.5 years after the OP, though...
Const FOF_CREATEPROGRESSDLG = &H0&
Dim ZipFile : ZipFile = "C:\vbscripted.zip"
Dim SrcFldrs : SrcFldrs = Array("D:\Documents and Settings\jimbobmcgee\My Documents")
With CreateObject("Scripting.Fi
.OpenTextFile ZipFile, 2, true
End With
With CreateObject("Shell.Applic
For each Fldr in SrcFldrs
'Copy the files to the compressed folder
.NameSpace(ZipFile).CopyHe
iFiles = iFiles + .NameSpace(Fldr).Items.Cou
'Keep script waiting until Compressing is done
On Error Resume Next
Do Until .NameSpace(ZipFile).Items.
wScript.Sleep 1000
Loop
On Error GoTo 0
Next
End With
Shame its 5.5 years after the OP, though...
The following is a link to a class that can be used in a VB6 application:
http://www.mvps.org/emorcillo/vb6/shell/xpzip.zip
Otherwise, you should download a command-line archiver, such as 7-Zip, and use that. You can get 7-Zip from:
http://www.7-zip.org/
HTH