Jijo Posted September 27, 2011 Share Posted September 27, 2011 I want to restart a process by checking a log file "C:\Documents and Settings\~\Desktop\New Folder\test.txt", so I have copied some code from this forum and created an immature script. But now I want to read a log file like "C:\Documents and Settings\~\Desktop\New Folder\test_yyyymmdd.txt" where yyyymmdd is year month and date (like 20110927). I have searched a lot but couldn't find anything what exactly required for me. #include <Date.au3> Local $TempFileDate = FileGetTime( "C:\Documents and Settings\~\Desktop\New Folder\test.txt", 0 ) Local $JobLastRun = $TempFileDate[0] & "/" & $TempFileDate[1] & "/" & $TempFileDate[2] & " " & $TempFileDate[3] & ":" & $TempFileDate[4] & ":" & $TempFileDate[5] if _DateDiff("s", $JobLastRun, _NowCalc()) >60 Then $PID = ProcessExists("notepad.exe") ; Will return the PID or 0 if the process isn't found. If $PID Then ProcessClose($PID) EndIf Run("notepad.exe") EndIf Could you please help me ? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 27, 2011 Moderators Share Posted September 27, 2011 Jijo, Welcome to the AutoIt forum. I think this should do what you want: expandcollapse popup#include <Date.au3> ; Write an initial log file FileWrite(@ScriptDir & "\test.txt", "fred") While 1 Local $TempFileDate = FileGetTime(@ScriptDir & "\test.txt", 0) Local $JobLastRun = $TempFileDate[0] & "/" & $TempFileDate[1] & "/" & $TempFileDate[2] & " " & $TempFileDate[3] & ":" & $TempFileDate[4] & ":" & $TempFileDate[5] If _DateDiff("s", $JobLastRun, _NowCalc()) > 10 Then $PID = ProcessExists("notepad.exe") ; Will return the PID or 0 if the process isn't found. If $PID Then ; Close the process ProcessClose($PID) ; Wait until process has closed While ProcessExists($PID) Sleep(10) WEnd ; Reopen the process Run("notepad.exe") ; Wait until it opens ProcessWait("notepad.exe") ; Rewrite the log file FileWrite(@ScriptDir & "\test.txt", "fred") ; Allow time for sytem to catch up Sleep(100) Else ; Open the process initially Run("notepad.exe") ; As above ProcessWait("notepad.exe") FileWrite(@ScriptDir & "\test.txt", "fred") Sleep(100) EndIf EndIf WEnd I changed the logfile path for testing - you will have to change it back. Please ask if anything is unclear. 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...
Jijo Posted September 28, 2011 Author Share Posted September 28, 2011 Hi Melba23, Thanks for the updated code. I will check this today and if there is anything not clear then surely I will request your help. Jijo Link to comment Share on other sites More sharing options...
Jijo Posted September 28, 2011 Author Share Posted September 28, 2011 Hi Melba23, how I can read a filename "C:\Documents and Settings\~\Desktop\New Folder\test_<<yyyymmdd>>.txt" where yyyymmdd changes daily. And how I can check its update time? The previous requirement was completed. Thanks for your help. Jijo Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 28, 2011 Moderators Share Posted September 28, 2011 Jijo, Create the filename like this - not sure if you want today or any given date so I have shown how to do both: $sYear = "1984" $sMon = "05" $sDay = "17" $sFileName = "C:\Documents and Settings\~\Desktop\New Folder\test_<<" & $sYear & $sMon & $sDay & ">>.txt" ConsoleWrite($sFileName & @CRLF) $sFileName = "C:\Documents and Settings\~\Desktop\New Folder\test_<<" & @YEAR & @MON & @MDAY & ">>.txt" ConsoleWrite($sFileName & @CRLF) and then use FileRead($sFileName). how I can check its update time?You used FileGetTime in the other script - why not use it again? 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...
Jijo Posted September 28, 2011 Author Share Posted September 28, 2011 Hi Melba23, Actually the second one suffice .. Thanks alot for your response. Jijo 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