Vbs mdb package and decommission code package

Source: Internet
Author: User

Pack. vbs is used to package folders. The root directory is the directory where the files are located.

Copy codeThe Code is 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 "the current directory has been packaged and the root directory is the 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 a Packet. mdb and unpack it to the current directory.Copy codeThe Code is 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"), faster Rev (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 have been 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

Packaging 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.