ECHAIGNE Posted July 17, 2004 Share Posted July 17, 2004 (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 July 17, 2004 by ECHAIGNE Link to comment Share on other sites More sharing options...
Somerset Posted July 17, 2004 Share Posted July 17, 2004 Nope, not possible. Jon told me while ago not built for binary reading. Link to comment Share on other sites More sharing options...
Lazycat Posted July 17, 2004 Share Posted July 17, 2004 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. Koda homepage ([s]Outdated Koda homepage[/s]) (Bug Tracker)My Autoit script page ([s]Outdated mirror[/s]) Link to comment Share on other sites More sharing options...
Somerset Posted July 18, 2004 Share Posted July 18, 2004 still it cannot read past EOF(End Of File). believe me i have tried, that or unless jon has changed it. Link to comment Share on other sites More sharing options...
pekster Posted July 18, 2004 Share Posted July 18, 2004 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 More sharing options...
ECHAIGNE Posted July 18, 2004 Author Share Posted July 18, 2004 Thank very much KOT, your function is OK for me Link to comment Share on other sites More sharing options...
ECHAIGNE Posted July 18, 2004 Author Share Posted July 18, 2004 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 More sharing options...
Lazycat Posted July 18, 2004 Share Posted July 18, 2004 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... 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. Koda homepage ([s]Outdated Koda homepage[/s]) (Bug Tracker)My Autoit script page ([s]Outdated mirror[/s]) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now