LarsJ Posted February 13, 2012 Share Posted February 13, 2012 Are there better ways to do it than this: #include <Array.au3> $file = FileOpen( "file.log", 16 ) ; Open the file in binary mode FileSetPos( $file, $lastFileSize+1, 0 ) ; Move filepointer forward $bytes = BinaryToString( FileRead( $file, $thisFileSize - $lastFileSize ) ) ; Read the new bytes FileClose( $file ) $aLines = StringSplit( $bytes, @CRLF, 3 ) ; Split the bytes into an array of lines _ArrayDisplay( $aLines ) Although it's simple code it's pretty fast. But I would like to know if there are more advanced methods to make it even faster. Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
UEZ Posted February 13, 2012 Share Posted February 13, 2012 (edited) Here another method: $hFile = FileOpen(@ScriptDir & "file.log") $string = FileReadLine($hFile, -1) FileClose($hFile) MsgBox(0, "Test", $string) I didn't benchmark it. _FileReadToArray() might be also a possibility whereas last element in array is the last line. Br, UEZ Edited February 13, 2012 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
LarsJ Posted February 13, 2012 Author Share Posted February 13, 2012 UEZ, The logfile can grow up till 2 GB. I record the filesize, so I know how many bytes is added, but I don't know how many lines. So FileReadLine and _FileReadToArray will not work in this case. After I read your post I tested how fast the method in post #1 is. Reading and splitting the last 100 KB (about 1000 lines) in a 1.2 GB logfile is done in 40 ms. Pretty fast with just build in commands. This can probably not be done any better. Lars. Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
UEZ Posted February 14, 2012 Share Posted February 14, 2012 (edited) I had a similar problem to read the result of the huge robocopy log file whereas I need only a few lines from the tail.Have a look to Br,UEZ Edited February 14, 2012 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
LarsJ Posted February 14, 2012 Author Share Posted February 14, 2012 Thank you. I have just downloaded your script. I had a short look at it some days ago. It matched a search for "FileSetPos". Lars. Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions 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