Seminko Posted August 26, 2014 Share Posted August 26, 2014 Hey fellas, I have this log file that looks like this: [18:45:12]: Stuff1 [18:45:23]: Stuff22 [18:45:23]: Stuff98 [19:02:37]: Stuff7 [19:02:38]: Stuff1 [19:02:38]: Stuff1324 ... What I need is a script that would periodically check the time in the log and if the difference between the last log entry and the current time is greater than X it would do Y. Is that something that could be done? Thanks a lot Link to comment Share on other sites More sharing options...
Moderators Solution Melba23 Posted August 26, 2014 Moderators Solution Share Posted August 26, 2014 Seminko,Not too difficult. Read the file into a variable (an array is probably best), extract the most recent time (either first or last entry) and get the difference from the current time. Functions you might need are:FileReadToArray_StringBetween_DateDiff_NowCalcGive it a go and see how you get on - you know where we are if you run into problems. 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...
Seminko Posted August 26, 2014 Author Share Posted August 26, 2014 (edited) Seminko, Not too difficult. Read the file into a variable (an array is probably best), extract the most recent time (either first or last entry) and get the difference from the current time. Functions you might need are:FileReadToArray _StringBetween _DateDiff _NowCalc Give it a go and see how you get on - you know where we are if you run into problems. M23 Hello Melba, nice seeing you again . Is there a way for the script to recognize the last udpated file in a folder? For some reason this does not work: While 1 Local $LastLine = FileReadLine ("Log-2014-08-26 18-45-12.txt", -1) Local $aArray = _StringBetween($LastLine, "[", "]") MsgBox(1, "aaa", $aArray) Sleep(5000) WEnd It returns nothing. When I let MsgBox show me $LastLine, it shows me the correct stuff: [19:31:17]: Stuff Alright - $aArray[0] Edited August 26, 2014 by Seminko Link to comment Share on other sites More sharing options...
Danyfirex Posted August 26, 2014 Share Posted August 26, 2014 (edited) Hi. look FileGetTime Look this. #include <Array.au3> #include <String.au3> Local $aArray = FileReadToArray("yourfilehere") For $i = 0 To UBound($aArray) - 1 $aArray[$i] = _StringBetween($aArray[$i], "[", "]")[0] Next _ArrayDisplay($aArray) Saludos Edited August 26, 2014 by Danyfirex Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
JohnOne Posted August 26, 2014 Share Posted August 26, 2014 (edited) Here is a short example on how to get your times compatible with _dateDiff() which gets the difference between dates or times. $aFile = FileReadToArray("MyLog.txt") For $i = 0 To UBound($aFile) - 1 ConsoleWrite(_Time_To_Date_Time($aFile[$i]) & @LF) Next Func _Time_To_Date_Time($Time) Return StringLeft(_NowCalc(), 10) & " " & _StringBetween($Time, "[", "]")[0] EndFunc EDIT: Or this might be easier to understand. $aTimes = _StringBetween(FileRead("MyLog.txt"), "[", "]") For $i = 0 To UBound($aTimes) - 1 ConsoleWrite(_Time_To_Date_Time($aTimes[$i]) & @LF) Next Func _Time_To_Date_Time($Time) Return StringLeft(_NowCalc(), 10) & " " & $Time EndFunc Edited August 26, 2014 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Seminko Posted August 26, 2014 Author Share Posted August 26, 2014 Here is a short example on how to get your times compatible with _dateDiff() which gets the difference between dates or times. $aFile = FileReadToArray("MyLog.txt") For $i = 0 To UBound($aFile) - 1 ConsoleWrite(_Time_To_Date_Time($aFile[$i]) & @LF) Next Func _Time_To_Date_Time($Time) Return StringLeft(_NowCalc(), 10) & " " & _StringBetween($Time, "[", "]")[0] EndFunc EDIT: Or this might be easier to understand. $aTimes = _StringBetween(FileRead("MyLog.txt"), "[", "]") For $i = 0 To UBound($aTimes) - 1 ConsoleWrite(_Time_To_Date_Time($aTimes[$i]) & @LF) Next Func _Time_To_Date_Time($Time) Return StringLeft(_NowCalc(), 10) & " " & $Time EndFunc Well done, thx Link to comment Share on other sites More sharing options...
Seminko Posted August 26, 2014 Author Share Posted August 26, 2014 Right, got the first part. Now I have to make the script open the correct file. Hi. look FileGetTime Look this. #include <Array.au3> #include <String.au3> Local $aArray = FileReadToArray("yourfilehere") For $i = 0 To UBound($aArray) - 1 $aArray[$i] = _StringBetween($aArray[$i], "[", "]")[0] Next _ArrayDisplay($aArray) Saludos Could you please provide and example of looking through a folder to identify the file that was modified last? Link to comment Share on other sites More sharing options...
JohnOne Posted August 26, 2014 Share Posted August 26, 2014 I think it's trivial enough for you to try. _FileListToArray() Loop FileGetTime() With a bit of testing. Sure you will get help, with any problems you might have. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Seminko Posted August 26, 2014 Author Share Posted August 26, 2014 Google tested it for me $last = 0 $sFolder = "F:\Stuff\Logs\" If @Error = 1 Then exit $aFiles = _FileListToArray($sFolder , "*" , 1) for $i = 1 to $aFiles[0] $time = filegettime($sFolder & "\" & $aFiles[$i] , 0 , 1) If $time > $last Then $newfile = $aFiles[$I] $last = $time EndIf next msgbox(0, '' , $newfile) God damn I still don't really understand loops ie for $i do bla bla... :-/ Link to comment Share on other sites More sharing options...
Seminko Posted August 26, 2014 Author Share Posted August 26, 2014 Thank you all fellas. Have a good one! Link to comment Share on other sites More sharing options...
JohnOne Posted August 26, 2014 Share Posted August 26, 2014 Ace. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. 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