Ho can i create Zip Files via command-line?
Can be done via WMI?
I don´t wann use WinZIP COmmand Line Add-On, because it is not freeware
Can i use VBScript to do that? Other "Lnaguage" maybe?
Ho can i create Zip Files via command-line?
Can be done via WMI?
I don´t wann use WinZIP COmmand Line Add-On, because it is not freeware
Can i use VBScript to do that? Other "Lnaguage" maybe?
How about a free command line ZIP utility instead of WinZIP?
Since Windows already knows how to deal with zip files to some extent you
might want to try the following. No external programs are needed. Believe it
or not the wscript.sleep at the end is important to make this work
correctly.
Const FOF_CREATEPROGRESSDLG = &H0&
Const MyZip = "C:\..\MyZipFile.zip"
Const File1 = "C:\..\File1.txt"
Const File2 = "C:\..\File2.txt"
Const MyDest = "C:\scratch"
'-------------- create empty zip file ---------
'Create the basis of a zip file.
CreateObject("Scripting.FileSystemObject") _
.CreateTextFile(MyZip, True) _
.Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)
'-------------- zip ---------------------------
'get ready to add files to zip
With CreateObject("Shell.Application")
'add files
.NameSpace(MyZip).CopyHere File1, FOF_CREATEPROGRESSDLG
.NameSpace(MyZip).CopyHere File2
End With
wScript.Sleep 1000
Here is some info you may find useful too
Tanks, i´ll try it
In this forum i found another Tip, in creating a Blank ZIP file with "PK"
bytes and 17 bytes with CHR(0)
I´ll try to see
============================================
Set Ag=Wscript.Arguments
username = CreateObject("Wscript.Shell").Environment("Process")("username")
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts =
fso.OpenTextFile(FilePath&"_forms\workforus\_uploads\"&"form_data.zip", 2,
vbtrue)
BlankZip = "PK" & Chr(5) & Chr(6)
For x = 0 to 17
BlankZip = BlankZip & Chr(0)
Next
ts.Write BlankZip
set objFolder = nothing
set objShell = nothing
Set fso = nothing
Set ts = nothing
Set objShell = CreateObject("Shell.Application")
Set WshShell = WScript.CreateObject("WScript.Shell")
Set
DestFldr=objShell.NameSpace(FilePath&"_forms\workforus\_uploads\"&"form_data.zip")
Set SrcFldr=objShell.NameSpace(FilePath&"_forms\workforus\_csv")
DestFldr.CopyHere (FilePath&"_forms\workforus\_csv")
============================================
It works great for small files, for large files i´ve added a Wscript.Echo
(Modal Button, with OK) and ionly works if i click the OK button after the
Zip proccess ( i can see a dialog box with a gauge indicating that the zipins
in on the way
Maybe it be necessary to use a higher number in the sleep directive
What´s the purpose of the Const MyDest = "C:\scratch"???
In any circunstances this line is used for something?
Const MyDest = "C:\scratch" was something I used and forgot to remove before
sending the example.
Hi, Your script really helped me... But how can i use wild cards like i want to add C:\*.id file to the created zip file how wud i do that n this script
(duplicated post)
Last edited by dunwich; 07-06-2009 at 04:31 AM.
Hi
Thank you for the code sample, it's quite useful.
Let me complete it a bit.
The way it is coded, the compression will run in background. If there is a lot of data to archive, the script will end while the compression is on-going, and the end of the script will destroy the compression object and cancel the compression.
Here is a bit of code to wait until the compression is finished.
' Add this in the begining:
' before start : delete existing archive if it exists
Dim fs
Set fs = CreateObject("Scripting.FileSystemObject")
If fs.FileExists(MyZip) Then fs.DeleteFile(MyZip)
' add this after the compression code from LJB
'the CreateTextFile will create the file with 22 bytes inside
' the NameSpace(MyZip).CopyHere will tell windows to insert compressed files in it. For that, windows will replace the file by some temp file, and the file will reappear only when it's finished.
' so the compression is finisshed when I can see the file, with a size > 22 bytes.
' code :
Dim fZipIsFinished
fZipIsFinished=0
While fZipIsFinished=0
If fs.FileExists(MyZip) Then
Dim h
Set h=fs.getFile(MyZip)
If h.size=22 Then
fZipIsFinished=0
' File created, compression did not start yet
Else
fZipIsFinished=1
'File created, compression finished
End If
Else
'File removed for compression, not yet recreated. compression is in progress
fZipIsFinished=0
End If
wScript.Sleep 1000
Wend
msgbox "Done"
'Limitation : if the compression is canceled (on the progress window),
'the script will not know it and wait forever. hence my remark below.
' end code
that's it. Hope it helps.
I wish I know how to remove the progress window, and make it ignore the read errors, because I want to use it to backup big file-systems, as a subtitute for tar.
But anyway for me, it does not quite reach my needs, because I need to produce multivolume, and in STORE compression mode, and with full windows attribute. Perl, cygwin etc are no good because they do not store all windows attributes.
> How about a free command line ZIP utility instead of WinZIP?
Ye's, there are the command line version of 7z, and zip.exe from Info-Zip. Both are free and great, but they do not do multivolume.
winzip does it but is not free. I have an old license of pkzip, but for Windows 3.1. Can you imagine ? It stores the files with names in 8.3 !
So I am still seacrhing...
Suggestions are welcome.
Have a look near the end of this thread:
http://www.tek-tips.com/viewthread.cfm?qid=1231429. Sample code is
given that should help you.
Hope that helps,
Mark D. MacLachlan
This thread has been helpful and I'd like to add the way to wait for the compression to end.
This seems to work:
Set file = winShell.NameSpace(zipFilePath)
file.CopyHere(pathToFile)
Do Until file.Items.Count >= 1
Wscript.Sleep(200)
Loop
In this example I'm adding only one file so the check is >= 1
Here is my solution for determining when the file is done zipping. It seems to work so far...
Code:'Get the current size of the zip file. Set zipFile = fileSystemObject.GetFile(zipFilePath) zipFileSize = zipFile.Size 'Add the file to the zip archive. CreateObject("Shell.Application").NameSpace(zipFilePath) _ .MoveHere file.Path, FOF_CREATEPROGRESSDLG zipFinished = False 'Wait for the file to finish zipping before we continue. Do Until zipFinished If fileSystemObject.FileExists(zipFilePath) Then If zipFile.Size > zipFileSize Then zipFinished = True End If Loop
Bookmarks