vbs mdb打包解包代码打包

所属分类: 脚本专栏 / vbs 阅读数: 1651
收藏 0 赞 0 分享

pack.vbs 用来打包文件夹, 根目录为文件所在目录.

复制代码 代码如下:

Dim n, ws, fsoX, thePath
Set ws = CreateObject("WScript.Shell")
Set fsoX = CreateObject("Scripting.FileSystemObject")
thePath = ws.Exec("cmd /c cd").StdOut.ReadAll() & "\"
i = InStr(thePath, Chr(13))
thePath = Left(thePath, i - 1)
n = len(thePath)
On Error Resume Next
addToMdb(thePath)
Wscript.Echo "当前目录已经打包完毕,根目录为当前目录"
Sub addToMdb(thePath)
Dim rs, conn, stream, connStr
Set rs = CreateObject("ADODB.RecordSet")
Set stream = CreateObject("ADODB.Stream")
Set conn = CreateObject("ADODB.Connection")
Set adoCatalog = CreateObject("ADOX.Catalog")
connStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=Packet.mdb"
adoCatalog.Create connStr
conn.Open connStr
conn.Execute("Create Table FileData(Id int IDENTITY(0,1) PRIMARY KEY CLUSTERED, thePath VarChar, fileContent Image)")
stream.Open
stream.Type = 1
rs.Open "FileData", conn, 3, 3
fsoTreeForMdb thePath, rs, stream
rs.Close
Conn.Close
stream.Close
Set rs = Nothing
Set conn = Nothing
Set stream = Nothing
Set adoCatalog = Nothing
End Sub
Function fsoTreeForMdb(thePath, rs, stream)
Dim i, item, theFolder, folders, files
sysFileList = "$" & WScript.ScriptName & "$Packet.mdb$Packet.ldb$"
Set theFolder = fsoX.GetFolder(thePath)
Set files = theFolder.Files
Set folders = theFolder.SubFolders
For Each item In folders
fsoTreeForMdb item.Path, rs, stream
Next
For Each item In files
If InStr(LCase(sysFileList), "$" & LCase(item.Name) & "$") <= 0 Then
rs.AddNew
rs("thePath") = Mid(item.Path, n + 2)
stream.LoadFromFile(item.Path)
rs("fileContent") = stream.Read()
rs.Update
End If
Next
Set files = Nothing
Set folders = Nothing
Set theFolder = Nothing
End Function

unpack.vbs 用来解包文件包(Packet.mdb), 解开到当前目录.
复制代码 代码如下:

Dim rs, ws, fso, conn, stream, connStr, theFolder
Set rs = CreateObject("ADODB.RecordSet")
Set stream = CreateObject("ADODB.Stream")
Set conn = CreateObject("ADODB.Connection")
Set fso = CreateObject("Scripting.FileSystemObject")
connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Packet.mdb;"

conn.Open connStr
rs.Open "FileData", conn, 1, 1
stream.Open
stream.Type = 1

On Error Resume Next

Do Until rs.Eof
theFolder = Left(rs("thePath"), InStrRev(rs("thePath"), "\"))
If fso.FolderExists(theFolder) = False Then
createFolder(theFolder)
End If
stream.SetEos()
stream.Write rs("fileContent")
stream.SaveToFile str & rs("thePath"), 2
rs.MoveNext
Loop

rs.Close
conn.Close
stream.Close
Set ws = Nothing
Set rs = Nothing
Set stream = Nothing
Set conn = Nothing

Wscript.Echo "所有文件释放完毕!"

Sub createFolder(thePath)
Dim i
i = Instr(thePath, "\")
Do While i > 0
If fso.FolderExists(Left(thePath, i)) = False Then
fso.CreateFolder(Left(thePath, i - 1))
End If
If InStr(Mid(thePath, i + 1), "\") Then
i = i + Instr(Mid(thePath, i + 1), "\")
Else
i = 0
End If
Loop
End Sub

打包下载地址 https://www.jb51.net/downtools/A%20SPAdmin%20V1.02.rar

更多精彩内容其他人还在看

用VBS实现的发送带Cookie的HTTP请求的代码

在昨天的《使用正确版本的XMLHTTP》中卖了个关子,ServerXMLHTTP的功能比XMLHTTP强大,你现在大概已经猜到了吧。没错,用ServerXMLHTTP可以在HTTP请求头中加入Cookie,而XMLHTTP不可以
收藏 0 赞 0 分享

校准系统时间的VBS代码

更新为自动判断时间格式,WIN7 XP测试通过,WIN8待测试,主要是通过获取百度的相关信息然后跟系统时间进行比较
收藏 0 赞 0 分享

VBS中获取系统本次及上次开关机时间的代码(WinXP/win2003/Win7兼容版)

获取系统本次及上次开关机时间的vbs代码,经测试兼容WinXP/win2003/Win7系统,喜欢的朋友可以收藏下
收藏 0 赞 0 分享

VBS合并一个文件夹里的TXT的实现代码

有时从网上的电子书网站上下载解压后。得到的是多个TXT文本。有没有办法把多个TXT合在一起看呢?写了个代码。不是很完美,欢迎高手批评指教。 我只是个菜鸟,需要大家的关怀才能进步哇
收藏 0 赞 0 分享

VBS 硬盘读写统计(分区读写统计)

用vbs实现的硬盘读写统计(分区读写统计)的实现代码,想学习vbs的朋友可以参考下
收藏 0 赞 0 分享

VBS实现工作表按指定表头自动分表

下面的VBS脚本就是实现的工作表按指定表头(由用户选择)自动分表功能。需要的朋友只要将要操作的工作表拖放到脚本文件上即可轻松实现工作表分表
收藏 0 赞 0 分享

VBS 修改远程桌面端口号的代码

仅有一个简单的功能——修改远程桌面端口。系统必须是XP。或许应该发到新手区
收藏 0 赞 0 分享

VBS 强制关闭Symantec Endpoint Protection的代码

很多企业电脑系统是Windows Xp,使用Windows server 2003 来控制,其中客户端得杀毒软件有不少是使用 Symantec Endpoint Protection
收藏 0 赞 0 分享

vbsTree VBS脚本模拟tree命令

用vbs输出一个文件夹的目录结构,喜欢的朋友可以测试下
收藏 0 赞 0 分享

Hardware_Info.vbs 获取硬件信息的VBS代码

代码没有技术水准,网上搜索有一大堆类似代码,关键是中文描述方式,支持多个硬盘、显卡、内存、声卡、网卡,CPU超频识别,支持cmd调用
收藏 0 赞 0 分享
查看更多