Alupis Posted February 10, 2012 Share Posted February 10, 2012 Is there a way to Prepend a line instead of appending? As in i want to open a text file i'm using as a log and want the latest entries to be written to the top of the log file isntead of at the bottom so I dont have to scroll down for days to see the latest entries? my solution right now is to open the file, read the contents, copy them to an array or temporary file, reopen the log file using mode 2 (erase previous contents), write the new line entry, then reopen the log file using mode 1 (append to end of file) and append the copied contents back into the log file. THis works, but of course is not very optimized and includes a lot of copying and writing of data and having to open and close the same file several times... and when the log file gets big... obviously this isn't very fast performance wise... Any other ways to do this? the FileOpen() function seems to only allow modes that either wipe all contents or append to the bottom... thanks! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 10, 2012 Moderators Share Posted February 10, 2012 Alupis, Adding something to the beginning of the file is always going to involve rewriting the entire file whatever method you use. How are you displaying the log file to read it? Would it not be easier to use Autoit to automatically display the end of it so you do not have to scroll? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Alupis Posted February 10, 2012 Author Share Posted February 10, 2012 hmm... bummer there is no way to prepend... the log file isn't generally opened for viewing very often... i run a batch of stuff through the script two times a day, and it makes up to about 50 new lines in the log each time... so the log file grows pretty quickly... I really only view the log when there has been a problem... which is pretty infrequent at thsi point since my script has matured for a while... but none-the-less, when there is a problem, i have to scroll through tons of stuff and it would be easier if it was just at the top of the log file when i opened it. its not mission-critical, but it woudl be nice. now, is it considered "best practice" to store the contents of the text log file into memory (like and $array) or to actually have it write to another temporary file before appending it back into the log? Both work, (YES, I've TESTED GUYS), I'm looking for waht is best practice that reduces the most possibliity for error or things to go wrong while providing the best performance... on my test machine... both seem to be similar performance but this could just be my computer. Just so I can learn, what is the reason autoit can not prepend? other than there isn't a pre-built funciton for it i mean... It woudl seem that if it could open teh file and then give enter a "return/enter" key at the top it would move everything down 1 line allowing for a new line to be writetn at the top. easier said than done i know... but if you know why please share... as stated, i'm trying to understand these things. Thank you in advance. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 10, 2012 Moderators Share Posted February 10, 2012 Alupis,what is the reason autoit can not prepend?As you have stated in your first post ("my solution right now") AutoIt can indeed do this - so why do you ask this pointless question? I have already explained above that adding something to the beginning of a file means you have to rewrite the whole file. You admitted that this was a pretty inefficient way to do business, so why should AutoIt have a built-in function to do it when other solutions - like displaying the file log file in a user-friendly manner with the final line visible - is much more elegant. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Alupis Posted February 10, 2012 Author Share Posted February 10, 2012 (edited) i think you misunderstood me a little... sorry... i know i can MAKE autoit do this... i was asking why there isn't a "function" that can just add to the beginging without having to rewrite the entire file? If i open the file manually, i can hit the "enter" key on my keyboard to skip a line, then i can add new data to the newelry created top line... my question is along the lines of why can autoit not do this? i'm just trying to understand for my own personal knowledge... as i'm sure there is a very good and logical reason as to why autoit is incapable of doing this same thing wihout having to rewrite the entire file... thanks. Edited February 10, 2012 by Alupis Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 10, 2012 Moderators Share Posted February 10, 2012 Alupis, After your behaviour in this and your other thread I am beginning to wonder if you are trolling us. For the third time, adding something to the beginning of a file means you have to rewrite the whole file. What do you think you are doing manually whan you add a line in an editor? Well, you you are forcing the editor to rewrite the whole file which, as you yourself pointed out, is inefficient. The requirement to do this is not very common becasue of the inefficiency - so AutoIt does not have a native function to do it. You can write a function to do it very easily (as you have said you have done) so AutoIt can indeed "do it". But as I have pointed out, there are much more elegant ways to deal with it. You said that you read the log infrequently - so why use a very inefficient method often to create the log as you think it shoudl be when you need only use the elegant "scroll to the bottom" method to display the log file once in a while? Which do you think is the better way to approach the problem. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Alupis Posted February 10, 2012 Author Share Posted February 10, 2012 (edited) M23, why did you post this?After your behaviour in this and your other thread I am beginning to wonder if you are trolling us. This is a completely separate thread, and a completely separate question and has nothign to do wth anythign else I have posted.I asked a simple question, which you have now ansered in your latest respnose (thank you)What do you think you are doing manually whan you add a line in an editor? Well, you you are forcing the editor to rewrite the whole file which, as you yourself pointed out, is inefficient. The requirement to do this is not very common becasue of the inefficiency - so AutoIt does not have a native function to do it.This answers my question. I had no idea that if i open notepad and skip a line down that notepad is really "rewritting" my entire file. This perfectly explains why this is inneficiant. But did you really need to respond in such a negative way? "For the third time..."... I'm trying to learn M23... Edited February 10, 2012 by Alupis Link to comment Share on other sites More sharing options...
Xandy Posted February 10, 2012 Share Posted February 10, 2012 (edited) When I appear bad the solution (whatever it is) is not to blame others, because that will never solve the issue.As you know you must rewrite the file with the new data.solved Edited February 10, 2012 by Xandy Human Male Programmer (-_-) Xandy About (^o^) Discord - Xandy Programmer MapIt (Tile world editor, Image Tile Extractor, and Game Maker) Link to comment Share on other sites More sharing options...
Alupis Posted February 10, 2012 Author Share Posted February 10, 2012 Thank you Xandy for the addition. Just for others who come to this thread later: AutoIT cannot Prepend data to a file because of how Text Editiors behave. When you add a blank line to the top of a text file, the editior is actually rewritting your entire file so that it may slide everything down 1 line. For this reason, AutoIT is not able to do this without having to rewrite the entire file (Unless you have autoit open the text editor and then add a blank line that way instead od using the Include # <FILE.au3> functions). This should sum-up for anyone why you can not prepend lines natively in AutoIT. I have learned, and now so have you. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 10, 2012 Moderators Share Posted February 10, 2012 Alupis, Seemingly unlike you, others are quite able to read the 3 posts above where I have explained this. If you were not already banned for your behaviour in the other thread this would have been enough to earn you a holiday. Learn how to behave here before you return.. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 14, 2012 Moderators Share Posted February 14, 2012 Alupsis, Just to show we do not hold grudges, here is what might well be a partial solution to your problem. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts