純vbs實(shí)現(xiàn)zip壓縮與unzip解壓縮函數(shù)代碼
更新時(shí)間:2011年01月21日 23:35:45 作者:
用VBS解壓ZIP文件,網(wǎng)上搜到的多數(shù)是調(diào)用WinRAR,一點(diǎn)技術(shù)含量也沒(méi)有。聽說(shuō)可以用純vbs實(shí)現(xiàn),特整理給大家,已經(jīng)過(guò)測(cè)試。喜歡的朋友可以測(cè)試下。
壓縮代碼:
復(fù)制代碼 代碼如下:
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
解壓縮代碼:
復(fù)制代碼 代碼如下:
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文件,網(wǎng)上搜到的多數(shù)是調(diào)用WinRAR,一點(diǎn)技術(shù)含量也沒(méi)有。Google一下“VBS 解壓ZIP”,第二是搜搜問(wèn)問(wèn)“vbs實(shí)現(xiàn)解壓縮zip文件”,滿意答案是“所以想用vbs來(lái)解壓這兩種格式的文件,至少要有兩種命令行解壓工具,否則是絕對(duì)不可以的”。絕對(duì)不可以的,回答的人好自信啊,笑而不語(yǔ)~
原文:http://demon.tw/programming/vbs-zip-file.html
http://demon.tw/programming/vbs-unzip-file.html
相關(guān)文章
VBScript 打造自己的遠(yuǎn)程CMDShell附使用教程
這個(gè)cmdshell需要結(jié)合nc進(jìn)行配合使用,現(xiàn)在肉雞上執(zhí)行cmdshell然后在本地上面運(yùn)行nc,注意看下面的參數(shù)2013-07-07
VBS教程:函數(shù)-DatePart 函數(shù)
VBS教程:函數(shù)-DatePart 函數(shù)...2006-11-11
VBS基礎(chǔ)篇 - vbscript Dictionary對(duì)象
Dictionary是存儲(chǔ)數(shù)據(jù)鍵和項(xiàng)目對(duì)的對(duì)象,其主要屬性有Count、Item、Key,主要方法有Add、Exists、Items、Keys、Remove、RemoveAll2018-05-05
Adsutil.vbs 在腳本攻擊中的妙用[我非我原創(chuàng)]
Adsutil.vbs 在腳本攻擊中的妙用[我非我原創(chuàng)]...2007-03-03
域內(nèi)計(jì)算機(jī)和用戶獲取實(shí)現(xiàn)vbs代碼
域內(nèi)計(jì)算機(jī)和用戶獲?。ㄞD(zhuǎn)自冰點(diǎn)極限-赤龍),學(xué)習(xí)vbs的朋友可以參考下。2010-11-11
VBS實(shí)現(xiàn)工作表按指定表頭自動(dòng)分表
下面的VBS腳本就是實(shí)現(xiàn)的工作表按指定表頭(由用戶選擇)自動(dòng)分表功能。需要的朋友只要將要操作的工作表拖放到腳本文件上即可輕松實(shí)現(xiàn)工作表分表2013-01-01

