昨天一個在落伍的朋友給的,一個站的所有文件和圖片以二進制的方式放進了數據庫裡,用下面的代碼可以把數據庫裡的文件和圖片還原出來。
把得到的數據庫名字改成ToMdb.mdb,然後把下面的代碼保存成VBS格式。放在同一個目錄下,執行這個VBS文件
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=ToMdb.mdb;"
conn.Open connStr
rs.Open "wz", conn, 1, 1
stream.Open
stream.Type = 1
On Error Resume Next
Do Until rs.Eof
thePath = rs("folder") & "\"
theFolder = Left(thePath, InStrRev(thePath, "\"))
If fso.FolderExists(theFolder) = False Then
createFolder(theFolder)
End If
stream.SetEos()
stream.Write rs("body")
stream.SaveToFile str & thepath & rs("file"), 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