vbs mdb打包解包代碼打包
pack.vbs 用來(lái)打包文件夾, 根目錄為文件所在目錄. 
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 "當(dāng)前目錄已經(jīng)打包完畢,根目錄為當(dāng)前目錄"
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 用來(lái)解包文件包(Packet.mdb), 解開到當(dāng)前目錄.
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
打包下載地址 //www.jb51.net/downtools/A%20SPAdmin%20V1.02.rar
上一篇:將WMI中的DateTime類型轉(zhuǎn)換成VBS時(shí)間的函數(shù)代碼
欄 目:vb
下一篇:VBS偽造HTTP-REFERER的實(shí)現(xiàn)方法
本文標(biāo)題:vbs mdb打包解包代碼打包
本文地址:http://www.jygsgssxh.com/a1/vb/7447.html
您可能感興趣的文章
- 01-10下載文件到本地運(yùn)行的vbs
 - 01-10VBS中的正則表達(dá)式的用法大全 <font color=red>原創(chuàng)&
 - 01-10VBS中SendKeys的基本應(yīng)用
 - 01-10VBScript教程 第十一課深入VBScript
 - 01-10用VBSCRIPT控制ONSUBMIT事件
 - 01-10VBScript語(yǔ)法速查及實(shí)例說(shuō)明
 - 01-10VBS中Select CASE的其它用法
 - 01-10VBScript教程 第七課使用條件語(yǔ)句
 - 01-10vbscript 可以按引用傳遞參數(shù)嗎?
 - 01-10VBScript教程 第二課在HTML頁(yè)面中添加VBscript代碼
 


閱讀排行
- 1C語(yǔ)言 while語(yǔ)句的用法詳解
 - 2java 實(shí)現(xiàn)簡(jiǎn)單圣誕樹的示例代碼(圣誕
 - 3利用C語(yǔ)言實(shí)現(xiàn)“百馬百擔(dān)”問(wèn)題方法
 - 4C語(yǔ)言中計(jì)算正弦的相關(guān)函數(shù)總結(jié)
 - 5c語(yǔ)言計(jì)算三角形面積代碼
 - 6什么是 WSH(腳本宿主)的詳細(xì)解釋
 - 7C++ 中隨機(jī)函數(shù)random函數(shù)的使用方法
 - 8正則表達(dá)式匹配各種特殊字符
 - 9C語(yǔ)言十進(jìn)制轉(zhuǎn)二進(jìn)制代碼實(shí)例
 - 10C語(yǔ)言查找數(shù)組里數(shù)字重復(fù)次數(shù)的方法
 
本欄相關(guān)
- 01-10下載文件到本地運(yùn)行的vbs
 - 01-10飄葉千夫指源代碼,又稱qq刷屏器
 - 01-10SendKeys參考文檔
 - 01-10什么是一個(gè)高效的軟件
 - 01-10VBS中的正則表達(dá)式的用法大全 &l
 - 01-10exe2swf 工具(Adodb.Stream版)
 - 01-10VBS中SendKeys的基本應(yīng)用
 - 01-10用VBSCRIPT控制ONSUBMIT事件
 - 01-10VBScript教程 第十一課深入VBScript
 - 01-10VBScript語(yǔ)法速查及實(shí)例說(shuō)明
 
隨機(jī)閱讀
- 08-05織夢(mèng)dedecms什么時(shí)候用欄目交叉功能?
 - 01-10delphi制作wav文件的方法
 - 04-02jquery與jsp,用jquery
 - 08-05dedecms(織夢(mèng))副欄目數(shù)量限制代碼修改
 - 01-11ajax實(shí)現(xiàn)頁(yè)面的局部加載
 - 08-05DEDE織夢(mèng)data目錄下的sessions文件夾有什
 - 01-10C#中split用法實(shí)例總結(jié)
 - 01-10使用C語(yǔ)言求解撲克牌的順子及n個(gè)骰子
 - 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文
 - 01-10SublimeText編譯C開發(fā)環(huán)境設(shè)置
 


