我想找到一大块文件的哈希值并将该哈希值保存在另一个文件中。我想直接做,而不必将块保存在单独的文件中..这是我的程序。
Const chunksize = 1024000000
dim istream,ostream
Sub WriteChunk(data)
Set oStream = CreateObject("ADODB.Stream")
oStream.Open
oStream.Type = 1
oStream.Write data
Dim WshShell, oExec, input,objfile2,str1
Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.exec("C:\Users\Administrator\desktop\experimenting\md5.exe_
-odup5.txt """ & ostream.write & """")
input = ""
Do While oexec.status=0
WScript.Sleep 50
Loop
oStream.Close
End Sub
Set iStream = CreateObject("ADODB.Stream")
iStream.Open
iStream.Type = 1 'binary
Const FOR_READING = 1
strFolder = "C:\test"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strFolder)
Set colFiles = objFolder.Files
For Each objFile In colFiles
iStream.LoadFromFile objfile.path
Do Until istream.EOS
WriteChunk iStream.Read(chunksize)
loop
Next
ShowSubFolders(objFolder)
Sub ShowSubFolders(objFolder)
Set colFolders = objFolder.SubFolders
For Each objSubFolder In colFolders
set colFiles = objSubFolder.Files
For Each objFile2 In colFiles
iStream.LoadFromFile objfile2.path
Do Until istream.EOS
WriteChunk iStream.Read(chunksize)
loop
Next
ShowSubFolders(objSubFolder)
Next
End Sub
iStream.Close
ostream.write不能用作参数。但我不知道什么可以用来代替那个......请帮助
答案 0 :(得分:0)
Set oExec = WshShell.exec("C:\Users\Administrator\desktop\experimenting\md5.exe_
-odup5.txt """ & ostream.write & """")
上述操作会失败,因为你不能在字符串中使用换行。此外,ostream.write
表示您正在尝试将写入 ADODB Stream对象。您实际想要做什么(假设我正确理解您的问题并且您正在使用this md5.exe
)是这样的:
WshShell.Run "C:\...\md5.exe -ochunk_md5.txt -d""" & data & """"
要将所有数据块的结果写入同一文件,请执行以下操作:
WshShell.Run "%COMSPEC% /c md5.exe -o- -d""" & data & """>chunk_md5.txt", 1, True
或者像这样:
Set md5 = WshShell.Exec("md5.exe -o- -d""" & data & """")
Do While md5.Status = 0
WScript.Sleep 100
Loop
objFSO.OpenTextFile("chunk_md5.txt", 8, True).Write md5.StdOut.ReadAll
或者您可以使用this VBScript来计算哈希并将结果写入文件。