Implementation of ZIP compression and unzip decompression function code _vbs for pure VBS

Source: Internet
Author: User
Tags chr

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.