Sign in to follow this  
Followers 0
ECHAIGNE

FileRead

8 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



Nope, not possible. Jon told me while ago not built for binary reading.


 

Spoiler

shoot_zpsfd329d66.png
dontbelieveeverythingyouthink_zps0e1e900

Madness is the first step to understanding...

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

still it cannot read past EOF(End Of File). believe me i have tried, that or unless jon has changed it.


 

Spoiler

shoot_zpsfd329d66.png
dontbelieveeverythingyouthink_zps0e1e900

Madness is the first step to understanding...

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Thank very much KOT, your function is OK for me

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
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
Sign in to follow this  
Followers 0