我如何在一个文件块中找到散列而不必将块保存在单独的文件中

我如何在一个文件块中找到散列而不必将块保存在单独的文件中

本文介绍了我如何在一个文件块中找到散列而不必将块保存在单独的文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为一个文件块找到一个散列并将该散列保存在另一个文件中。我想直接做,而不必将块保存在单独的文件中。这是我的程序。

  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(st rFolder)

设置colFiles = objFolder.Files

对于每个objFile在colFiles中
iStream.LoadFromFile objfile.path
Do直到istream.EOS
WriteChunk iStream.Read(chunksize)


循环


下一个

ShowSubFolders(objFolder)


Sub ShowSubFolders(objFolder)

设置colFolders = objFolder.SubFolders

对于每个objSubFolder在colFolders中

set colFiles = objSubFolder.Files

对于每个objFile2在colFiles中


iStream.LoadFromFile objfile2.path
Do直到istream.EOS
WriteChunk iStream.Read(chunksize)



循环
下一个

ShowSubFolders(objSubFolder)

下一个

End Sub


iStream.Close



ostream.write不能用作参数。但我不理解什么可以用来代替那个..请帮助解决方案

Set oExec = WshShell.exec(C:\ Users \Administrator\desktop\experimenting\md5.exe_
-odup5.txt& ostream.write& )

以上将失败,因为您不能在字符串中使用换行符。此外, ostream.write 表示您正在尝试将写入 ADODB Stream对象。你真正想要做什么(假设我正确理解你的问题,并且你正在使用 <$ c
$ b

  WshShell.RunC:\\ c> md5.exe )是这样的:

\\ ... \md5.exe -chunk_md5.txt -d&数据&

要将所有数据块的结果写入同一个文件,这:

  WshShell.Run%COMSPEC%/ c md5.exe -o- -d&数据& > 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

或者您可以使用用于计算哈希值并将结果写入文件。


I want to find a hash for a chunk of file and save that hash in another file. I want to do it directly without having to save the chunk in a separate file.. here is my program.

 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 cannot be used as an argument. But i am not understanding as to what can be used instead of that..please help

解决方案
Set oExec = WshShell.exec("C:\Users\Administrator\desktop\experimenting\md5.exe_
                     -odup5.txt """ & ostream.write & """")

The above will fail, because you can't use line-wrapping inside strings. Also, ostream.write means you're trying to write something to an ADODB Stream object. What you actually want to do (assuming I understood your question correctly and you're using this md5.exe) is something like this:

WshShell.Run "C:\...\md5.exe -ochunk_md5.txt -d""" & data & """"

To write the results of all chunks of data to the same file, do something like this:

WshShell.Run "%COMSPEC% /c md5.exe -o- -d""" & data & """>chunk_md5.txt", 1, True

or like this:

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

Or you could use this VBScript for calculating the hash and write the result to a file.

这篇关于我如何在一个文件块中找到散列而不必将块保存在单独的文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 23:55