您好,登錄后才能下訂單哦!
本篇內容主要講解“vbs實現zip壓縮與unzip解壓縮函數的代碼分享”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“vbs實現zip壓縮與unzip解壓縮函數的代碼分享”吧!
壓縮代碼:
復制代碼 代碼如下:
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(18, 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
Do
WScript.Sleep 1000
Loop Until objTarget.Items.Count > 0
End Sub
解壓縮代碼:
復制代碼 代碼如下:
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
到此,相信大家對“vbs實現zip壓縮與unzip解壓縮函數的代碼分享”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續(xù)學習!
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。