Jump to content

Problem with getting Binary


Recommended Posts

I'm working on a script that compares the binary information of multiple files

the following is a function that I am creating to add the binary information to an array

Func _FilesBinary($iFileArray)
    $iBinary = _ArrayCreate(UBound($iFileArray) - 1)
    For $i = 1 To $iBinary[0]
        $iRead = FileOpen($iFileArray[$i], 16)
        $iBinaryTemp = FileRead($iRead)
        _ArrayAdd($iBinary, $iBinaryTemp)
    Next
    Return $iBinary
EndFunc

I can't figure out what I did wrong but it only adds the information to the last element

Link to comment
Share on other sites

I'm working on a script that compares the binary information of multiple files

the following is a function that I am creating to add the binary information to an array

Func _FilesBinary($iFileArray)
    $iBinary = _ArrayCreate(UBound($iFileArray) - 1)
    For $i = 1 To $iBinary[0]
        $iRead = FileOpen($iFileArray[$i], 16)
        $iBinaryTemp = FileRead($iRead)
        _ArrayAdd($iBinary, $iBinaryTemp)
    Next
    Return $iBinary
EndFunc

I can't figure out what I did wrong but it only adds the information to the last element

I would try something like this.

CODE
Func _FilesBinary($iFileArray)

$iBinary = _ArrayCreate(UBound($iFileArray))

For $i = 1 To $iBinary[uBound($iFileArray) - 1]

$iRead = FileOpen($iFileArray[$i], 16)

$iBinaryTemp = FileRead($iRead)

_ArrayAdd($iBinary, $iBinaryTemp)

Next

Return $iBinary

EndFunc

I believe that when you are calling $iBinary[0] it is only doing the last element in the array, but I could be wrong.

Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.

Link to comment
Share on other sites

It works fine for me. To test, I used..

#include "Include\corz_essentials.au3"
#include <Array.au3>
$FileArray = RecurseDir("I:\work\dev\autoit\test\smallfiles", "*.*")
PrintArray($FileArray,  "$foo")
$foo = _FilesBinary($FileArray)
PrintArray($foo,  "$foo")

Func _FilesBinary($iFileArray)
    $iBinary = _ArrayCreate(UBound($iFileArray) - 1)
    For $i = 1 To $iBinary[0]
        $iRead = FileOpen($iFileArray[$i], 16)
        $iBinaryTemp = FileRead($iRead)
        _ArrayAdd($iBinary, $iBinaryTemp)
    Next
    Return $iBinary
EndFunc
exit

;o)

(or

nothing is foolproof to the sufficiently talented fool..

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...