Andre Posted October 6, 2004 Posted October 6, 2004 Hi,Im trying to read an binary file (.mdb) with FileReadI want to know if the read file is created with an old or new version of msaccess.With an texteditor i can see that in the header of an access file is some text likeStandard Jet 4.0 for example $File = FileOpen($AccessFile,0) ; Check if file opened for reading OK If $File = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ; Read first 159 bytes to see which msaccess version is needed. $Line = FileRead($File,2048) If @error <> 0 Then MsgBox(0, "Error", "Unable to open file.") $Position = StringInStr($Line, "4.0", 1) MsgBox(4096,"pos",$Position) FileClose($File)My $Position is always 0 What is wrong ?Andre What about Windows without using AutoIt ?It would be the same as driving a car without an steering Wheel!
sugi Posted October 6, 2004 Posted October 6, 2004 Im trying to read an binary file (.mdb) with FileReadThat's the problem. Binary files are not supported as far as I know. If you're using NT4+ you could try using the commands type and find for this (something like RunWait(@ComSpec & ' /c type file.mdb | find "4.0", '', @SW_HIDE)) and check the result.
Andre Posted October 6, 2004 Author Posted October 6, 2004 Hmm, Thats not what i want. Because the file i want to search through are big network files >= 500 Mb so find is then sloooooowwwwww Andre What about Windows without using AutoIt ?It would be the same as driving a car without an steering Wheel!
sugi Posted October 6, 2004 Posted October 6, 2004 There's another possibility: Read the file byte for byte (FileRead will return 0 when it encounters a 0-byte but AutoIt cannot store this 0-byte in its variables). Try this code:$String = '4.0' $searchpos = 1 $stringlength=StringLen($String) $FD=FileOpen('file.mdb', 0) For $i = 1 to 2048; only search within first 2048 byte $binary = Asc(FileRead($FD, 1)) if @error then exitloop; end search on eof or error if $binary = asc(stringmid($String, $searchpos, 1)) then $searchpos = $searchpos + 1; we found one character! if $searchpos > $stringlength then MsgBox(0, 'Match', 'string found'); we found the complete string FileClose($FD) exitloop endif continueloop; part of string found but not all. continue search with next character. else $searchpos = 1; this is a bug but should work for demonstration. details below endif next I did not test this code and it has (at least) one bug in it but since it's only for demonstration... What I'm doing is to read one character from the file, then check if the character matches the first character from the string. If it matches, i compare the second character to the string against the second character I read from the file and after that the third one. Problem is, when I have a file that contains '44.0' and the searchstring is '4.0'. My loop will not find the data since it compares 4=4, 4=. and then makes an error: it doesn't match and then does not go back to compare the second character (4) with the first character of the search string (4) but just continues to compare the next character (.) with the first character from the search string (4) and after that is unable to find a match. If you need a function that does not make this error, use an array to read the data. Then you'll be able to jump back.
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