Dave in PNG Posted April 23, 2007 Posted April 23, 2007 I have a whole slew of binary files that I need to read only the last 128 bytes of. Now I know I can do this to get to nearly the end of the files: FileRead($hfile,FileGetSize($Filename)-128) Now if a function like FileSeek() existed, would it be faster than performing a FileRead()? Just wondered.
Proph Posted April 23, 2007 Posted April 23, 2007 I have a whole slew of binary files that I need to read only the last 128 bytes of. Now I know I can do this to get to nearly the end of the files: FileRead($hfile,FileGetSize($Filename)-128) Now if a function like FileSeek() existed, would it be faster than performing a FileRead()? Just wondered. How large are the files you are trying to read? You can read the entire file by doing something like this: $size = FileGetSize("C:\yourfile.txt") $string = FileRead("C:\yourfile.txt") This will read the entire file in one quick run. Then you can use If StringInStr($string, "Whatever you search for") I'm not exactly sure what you are tring to accomplish.
Dave in PNG Posted April 23, 2007 Author Posted April 23, 2007 (edited) In C (which I've spent a number of years in) seeking to a position in the file is way faster than reading to that position. Basicially I'm trying to improve on the performance of some AutoIt code that needs to read the tail of a binary file (30K-10M). Right now I read almost to the end of the file throwing away the data so I can read what I need to get at. Now knowing how this part of the AutoIt implementation works, I just wondered if a FileSeek() function could be created by the developers or someone else that just moves the file position pointer on an already opened file rather than just actually reading the data. Thanks. Edited April 23, 2007 by Dave in PNG
randallc Posted April 23, 2007 Posted April 23, 2007 Hi, There is larry and Zedna's FileSetPos and ApiRead; linked from my "TailRW" link in signnature, i think.. Best, Randall ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW
Dave in PNG Posted April 23, 2007 Author Posted April 23, 2007 It's a binary file, so I don't see how this would work. Dave
randallc Posted April 23, 2007 Posted April 23, 2007 (edited) Hi,I did not intend you to use the function I wrote for __FileReadLine"; as it counts lines in the binary read; But I believe this does read binary?; maybe PM Zedna as he understands it better than I?[if yiou work it out, can you share answers please? -];_FileSeek.au3 #include "TailRW.au3" $s_File = @WindowsDir&"\Rhododendron.bmp" $h_File = _APIFileOpen ($s_File);1 _APIFileSetPos ($h_File, FileGetSize($s_File)-128);5 ;read first $s_TextReadBin = _APIFileRead ($h_File, 128);*** Does this need to be a binary string? [** EDIT -needs 3rd parm=1 for binary - not this script] _APIFileClose ($h_File) MsgBox(0,"","StringLen($s_TextReadBin)="&StringLen($s_TextReadBin)); ids there a way of displaying the binary read value or length?Best, randall[EDIT] - I found the script thread; fileSePos later in thread;Binary File Read/Write[EDIT 2] - yes, maybe you need "_BinaryFileRead(ByRef $hFile, ByRef $buff_ptr, $buff_bytes = 0)" which was added by EriFash to that UDF?[EDIT 3] - or maybe it is not possible to modify it enough! - I think you might be able to...? Edited April 23, 2007 by randallc ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW
randallc Posted April 23, 2007 Posted April 23, 2007 Hi, Maybe this?; - or make your own variant of the UDF funcs... ;ExBinRead.au3 #include "TailRW.au3" Local $e $s_File = @WindowsDir & "\Rhododendron.bmp" $i_FileSize = FileGetSize($s_File) $h_File = _APIFileOpen ($s_File) _APIFileSetPos ($h_File, $i_FileSize - 128);5 ;read first $d = _APIFileRead ($h_File, 128, 1) _APIFileClose ($h_File) $d = StringSplit($d, ",") For $i = 1 To $d[0] $e &= Chr("0x" & $d[$i]) Next MsgBox(4096, "", $e)Randall ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW
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