Jump to content

FileRead


Recommended Posts

Hello

It's there a possibility to read a binary file with FileRead ?

$hOpen = FileOpen($FichierGUID, 0)

$Text = FileRead($hOpen, FileGetSize($FichierGUID))

FileClose($hOpen)

When I try to do this, I can read until the first &h0 and I want read the total lenght of the file.

Excuse me for my bad english

Thank you for your answer

Eric

Edited by ECHAIGNE
Link to comment
Share on other sites

You still can read file byte-by-byte. If you need some textual information from binary file, you can try this UDF (I've used this for getting info from EXIF):

Func _FileReadAtOffset ($file, $offset, $bytes)
    $tfile = FileOpen($file, 0)
    $tstr = ""
    for $i = 1 to $offset
        FileRead($tfile, 1)
    next
    for $i = 1 to $bytes
        $tstr =  $tstr & FileRead($tfile, 1)
    next
    FileClose($tfile)
    return ($tstr)
Endfunc

Moreover, you can convert each byte into HEX-values and you will get HEX representation of binary file.

Link to comment
Share on other sites

How about this for an interesting solution: you could read each byte into an array (expanding as you go.) That way the nulls that would normally terminate the string would simply be an element of the array and not terminate the string. Or, if you don't need to read the nulls, just ignore them as you read them into a string.

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Link to comment
Share on other sites

This function, based on the function of KOT, put the content of the binary file into a array

Dim $Test[FileGetSize("C:\Test.txt") + 1]

_FileReadAtOffsetToArray($Test, "C:\Test.txt", 0, FileGetSize("C:\Test.txt"))

Func _FileReadAtOffsetToArray(ByRef $Binaire, $file, $offset, $bytes)

Local $tfile, $i

$tfile = FileOpen($file, 0)

For $i = 1 to $offset

FileRead($tfile, 1)

Next

For $i = 1 to $bytes

$Binaire[$i] = FileRead($tfile, 1)

$Binaire[0] = $i

Next

FileClose($tfile)

EndFunc

Link to comment
Share on other sites

still it cannot read past EOF(End Of File).

I believe, but in many cases (at least mine) this enough. And I'm still waiting when plugins will be available... :ph34r:

How about this for an interesting solution: you could read each byte into an array (expanding as you go.)

Nice solution!

Although I usually use HEX representation, because then I can write file back with my primitive utility, this will allow convenient direct access to any byte.

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...