当前位置: 移动技术网 > IT编程>脚本编程>VBScript > 纯vbs实现zip压缩与unzip解压缩函数代码

纯vbs实现zip压缩与unzip解压缩函数代码

2017年12月08日  | 移动技术网IT编程  | 我要评论

toupaizouguang,兵天血地,梦回古朝

压缩代码:

复制代码 代码如下:

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文件,网上搜到的多数是调用winrar,一点技术含量也没有。google一下“vbs 解压zip”,第二是搜搜问问“vbs实现解压缩zip文件”,满意答案是“所以想用vbs来解压这两种格式的文件,至少要有两种命令行解压工具,否则是绝对不可以的”。绝对不可以的,回答的人好自信啊,笑而不语~
原文:http://demon.tw/programming/vbs-zip-file.html
http://demon.tw/programming/vbs-unzip-file.html

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网