Frage

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

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top