Zip Code:
Copy Code code as follows:
Zip "D:\test.iso", "D:\test.zip"
Zip "D:\test", "D:\test.zip"
Msgbox "OK"
Sub Zip (ByVal mysourcedir, ByVal myzipfile)
Set fso = CreateObject ("Scripting.FileSystemObject")
If FSO. Getextensionname (myzipfile) <> "Zip" Then
Exit Sub
ElseIf FSO. FolderExists (Mysourcedir) Then
FType = "Folder"
ElseIf FSO. FileExists (Mysourcedir) Then
FType = "File"
FileName = fso. GetFileName (Mysourcedir)
FolderPath = Left (Mysourcedir, Len (mysourcedir)-Len (FileName))
Else
Exit Sub
End If
Set f = fso. CreateTextFile (Myzipfile, True)
F.write "PK" & Chr (5) & Chr (6) & String (Chr (0))
F.close
Set Objshell = CreateObject ("Shell.Application")
Select Case Ftype
Case "Folder"
Set Objsource = Objshell.namespace (Mysourcedir)
Set objFolderItem = Objsource.items ()
Case "File"
Set Objsource = Objshell.namespace (FolderPath)
Set objFolderItem = Objsource.parsename (FileName)
End Select
Set objtarget = Objshell.namespace (myzipfile)
Intoptions = 256
Objtarget.copyhere objFolderItem, Intoptions
Todo
Wscript.Sleep 1000
Loop Until objTarget.Items.Count > 0
End Sub
To extract the code:
Copy Code code as follows:
UnZip "D:\test.iso", "D:\test.zip"
Msgbox "OK"
Sub CopyFolder (ByVal mysourcedir, ByVal mytargetdir)
Set fso = CreateObject ("Scripting.FileSystemObject")
If not FSO. FolderExists (Mysourcedir) Then
Exit Sub
ElseIf not FSO. FolderExists (Mytargetdir) Then
Fso. CreateFolder (Mytargetdir)
End If
Set Objshell = CreateObject ("Shell.Application")
Set Objsource = Objshell.namespace (Mysourcedir)
Set objFolderItem = Objsource.items ()
Set objtarget = Objshell.namespace (Mytargetdir)
Intoptions = 256
Objtarget.copyhere objFolderItem, Intoptions
End Sub
Extract the zip file with the VBS, most of the online search is called WinRAR, a bit of technical content is not. Google the "VBS extract ZIP", the second is search to ask "VBS implementation decompression ZIP file", satisfied with the answer is "so want to use the VBS to extract the two formats of the file, at least two command line decompression tool, otherwise it is absolutely not possible." Absolutely not, the answer to the people good self-confidence ah, laugh and not language ~
Original: http://demon.tw/programming/vbs-zip-file.html
Http://demon.tw/programming/vbs-unzip-file.html