smashly Posted January 8, 2007 Share Posted January 8, 2007 I'm trying to read a file over 350mb. I only need to read the first 7000000 characters at the beginning of the file and I have no problem. But trying to read the characters at the end of a file I'm having no success. Is there an easy method to either split my input file to more feasable sizes to read (without reading the whole file begiining to end)? or a way to read a file from the end backwards (without reading the whole file from beginning end) ? Any input is apreciated. Yes I have been reading the Autoit help file as well as forum searches but I'm no closer then when I started researching :/ (started 4 days ago) Thank You N Cheers Link to comment Share on other sites More sharing options...
Uten Posted January 8, 2007 Share Posted January 8, 2007 (edited) 350MB is quite a loot.. Is it plain text? Think you have to dig up some of the File UDF's that are lying around. I know I have seen some signatures with file udf's in them. Or wrap up the native API's yourself. If _FileCountLines are fast enough you might use something like this? NOTE: I have not tested the code. Func FileTail($file, $lines) Local $count = _FileCountLines($file) Local $i, $data For $i = $count - $lines to $count $data += filereadline($file, $count) If @error then ExitLoop Next Return $data EndFunc EDIT: Added $data declaration. Edited January 8, 2007 by Uten Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling Link to comment Share on other sites More sharing options...
smashly Posted January 8, 2007 Author Share Posted January 8, 2007 Thank You for the response Uten. I have tried _FileCountLines udf, but it fails as the file is to big I gather. I was reading binary data (even though FileRead says it's only for text), I find FileRead works fine for binary data as long as the file being read isn't to big. I was extracting *.png files out of a file that can be anything from 100MB upto 1.6GB by using the header and footer of the *.png and using StringInStr, StringTrimLeft or Right and writing the data to a new file (new png is only about 200-300kb) As the file strucure of the files I'm working with only have the *.png's in the first 7000000 characters and in the last 7000000 characters of the file and the data in the middle is redundant to me, I was hoping there was a way to read from the end back without actually having to parse the input file from the beginning. Gather I'll have to look into api udfs abit more to get it sussed out. PS. I'm still using your tray TrayMenuEx.au3 udf, one of my favorite udfs Thank You Cheers Link to comment Share on other sites More sharing options...
Mast3rpyr0 Posted June 18, 2007 Share Posted June 18, 2007 (edited) could i see the source of this. im trying to do somewhat of the same thing. EDIT: sorry for bringing back such an old post Edited June 18, 2007 by Mast3rpyr0 My UDF's : _INetUpdateCheck() My Programs : GameLauncher vAlpha, InfoCrypt, WindowDesigner, ScreenCap, DailyRemindersPick3GeneratorBackupUtility! Other : Bored? Click Here! Link to comment Share on other sites More sharing options...
randallc Posted June 18, 2007 Share Posted June 18, 2007 Hi, I think the newest version of my Tail works; eg this reads the thirds of a bmp in any order, then puts the splices back together; Best, Randall ;apitry.au3 #include "APITailRW.au3" Local $sDeskFile = @DesktopDir & "\Rhododendron.bmp", $s_File = @WindowsDir & "\Rhododendron.bmp" FileDelete($sDeskFile) $i_FileSize = FileGetSize($s_File) ;======Read parts or tail of binary file =====in any order================================= $h_File = _FileOpenAPI ($s_File) ;_APIFileOpen $s_data3 = _FileReadAPI ($h_File, Int($i_FileSize / 3) + 2, 2 * Int($i_FileSize / 3), 1) ; read 3rd third file $s_data2 = _FileReadAPI ($h_File, Int($i_FileSize / 3), Int($i_FileSize / 3), 1) ; read 2nd third file $s_data1 = _FileReadAPI ($h_File, Int($i_FileSize / 3), 0, 1) ; read 1st third file $s_data = $s_data1 & $s_data2 & $s_data3 ; concatenate in correct order _FileCloseAPI ($h_File);_APIFileClose ;======Save binary file to desktop and open====================================== $ha_File = FileOpen($sDeskFile, 18) FileWrite($ha_File, $s_data) FileClose($ha_File) ShellExecuteWait($sDeskFile) FileDelete($sDeskFile) ;============================================ ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW Link to comment Share on other sites More sharing options...
Mast3rpyr0 Posted June 18, 2007 Share Posted June 18, 2007 thanks that helps me out alot My UDF's : _INetUpdateCheck() My Programs : GameLauncher vAlpha, InfoCrypt, WindowDesigner, ScreenCap, DailyRemindersPick3GeneratorBackupUtility! Other : Bored? Click Here! Link to comment Share on other sites More sharing options...
JSunn Posted June 21, 2007 Share Posted June 21, 2007 Hi, I think the newest version of my Tail works; eg this reads the thirds of a bmp in any order, then puts the splices back together; Best, Randall ;apitry.au3 #include "APITailRW.au3" Local $sDeskFile = @DesktopDir & "\Rhododendron.bmp", $s_File = @WindowsDir & "\Rhododendron.bmp" FileDelete($sDeskFile) $i_FileSize = FileGetSize($s_File) ;======Read parts or tail of binary file =====in any order================================= $h_File = _FileOpenAPI ($s_File) ;_APIFileOpen $s_data3 = _FileReadAPI ($h_File, Int($i_FileSize / 3) + 2, 2 * Int($i_FileSize / 3), 1) ; read 3rd third file $s_data2 = _FileReadAPI ($h_File, Int($i_FileSize / 3), Int($i_FileSize / 3), 1) ; read 2nd third file $s_data1 = _FileReadAPI ($h_File, Int($i_FileSize / 3), 0, 1) ; read 1st third file $s_data = $s_data1 & $s_data2 & $s_data3 ; concatenate in correct order _FileCloseAPI ($h_File);_APIFileClose ;======Save binary file to desktop and open====================================== $ha_File = FileOpen($sDeskFile, 18) FileWrite($ha_File, $s_data) FileClose($ha_File) ShellExecuteWait($sDeskFile) FileDelete($sDeskFile) ;============================================ Thanks RandallC! I'm not the original poster but you helped me out a ton also. I am working on a utility to split MP3's using CUE files and tagging them at the same time (mostly to help organize my massive music collection) and after the new binary functions were added my FileOpen (for binary files) pretty much stopped working with the new version 3.2.4.9. Your (and others) code saved the day.. Thanks again! -J Link to comment Share on other sites More sharing options...
randallc Posted June 21, 2007 Share Posted June 21, 2007 ok!my FileOpen (for binary files) pretty much stopped workinghow was it doing this before that it won't now? i don't think Fileopen binary has lost any functionality?...Best, randall ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW 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