欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

用VBScript实现压缩目录中的所有文件(Zip)

程序员文章站 2022-07-04 20:34:12
复制代码 代码如下:on error resume next dim objfso,sourcepath,targetpath,targetfile function ge...
复制代码 代码如下:

on error resume next
dim objfso,sourcepath,targetpath,targetfile

function getsourcefile(path)
dim file,folder,sfolder,subfolder,files
if not objfso.folderexists(path) then
msgbox "目标文件夹不存在!"
else
objfso.createfolder targetpath & right(path,len(path)-len(sourcepath))
set folder=objfso.getfolder(path)
set files=folder.files
for each file in files
targetfile=targetpath & right(path,len(path)-len(sourcepath)) & "\" & file.name & ".zip"
set fp=objfso.opentextfile(targetfile,2,true)
fp.write chr(80) & chr(75) & chr(5) & chr(6) & string(18,0)
fp.close
oapp.namespace(targetfile).copyhere path & "\" & file.name
wscript.sleep 1000
next
set subfolder=folder.subfolders
for each sfolder in subfolder
getsourcefile path & "\" & sfolder.name
next
end if
end function

set objfso=createobject("scripting.filesystemobject")
set oapp=createobject("shell.application")
sourcepath="c:\documents and settings\administrator\桌面\watermarks"
targetpath="d:\temp"
getsourcefile sourcepath
set objfso=nothing
set oapp=nothing

使用方法:
直接将上面的代码保存为test.vbs文件,然后修改sourcepath与targetpath注意目标目录必须是新目录,使用的时候最好加上判断。