VBS MDB Package Unpack code package _vbs

Source: Internet
Author: User
Tags unpack

Pack.vbs is used to package folders, and the root directory is the directory where the files reside.

Copy Code code as follows:

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 "Current directory is packaged, root directory is current directory"
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 is used to unpack the package (Packet.mdb) and unpack to the current directory.
Copy Code code as follows:

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 "All Files released!"

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

Package Download Address Http://www.jb51.net/downtools/A%20SPAdmin%20V1.02.rar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.