码迷,mamicode.com
首页 > 其他好文 > 详细

vbs实现zip压缩

时间:2018-12-27 03:36:58      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:span   sts   sele   item   ring   ica   ext   pre   text   

VBS实现zip压缩

Zip "D:\test.xls", "D:\test.zip" 
 
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 

 

vbs实现zip压缩

标签:span   sts   sele   item   ring   ica   ext   pre   text   

原文地址:https://www.cnblogs.com/javier520/p/10182555.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!