jerem488 Posted July 28, 2009 Share Posted July 28, 2009 Hello, I have a text file like this : c:\Documents and Settings\ADMIN\Application Data\Microsoft\Internet Explorer\brndlog.bak 1 KB 02/01/2008 14:35:51 c:\Documents and Settings\ADMIN\Local Settings\Application Data\Microsoft\Internet Explorer\brndlog.bak 8 KB 13/10/2008 14:29:02 c:\Documents and Settings\administrateur\Application Data\Microsoft\Internet Explorer\brndlog.bak 1 KB 02/01/2008 14:35:51 and I want to read the day, month and year of each line. After if the date is exceeded by 5 days, we put a msgbox. But the problem is especially to read the date of each line. Thanks Qui ose gagneWho Dares Win[left]CyberExploit[/left] Link to comment Share on other sites More sharing options...
99ojo Posted July 28, 2009 Share Posted July 28, 2009 Hello, I have a text file like this : c:\Documents and Settings\ADMIN\Application Data\Microsoft\Internet Explorer\brndlog.bak 1 KB 02/01/2008 14:35:51 c:\Documents and Settings\ADMIN\Local Settings\Application Data\Microsoft\Internet Explorer\brndlog.bak 8 KB 13/10/2008 14:29:02 c:\Documents and Settings\administrateur\Application Data\Microsoft\Internet Explorer\brndlog.bak 1 KB 02/01/2008 14:35:51 and I want to read the day, month and year of each line. After if the date is exceeded by 5 days, we put a msgbox. But the problem is especially to read the date of each line. Thanks Hi, maybe another one with more StringRegExp experience have a better way, but this will give you a good start: #include <array.au3> #include <file.au3> $filetext = _FileReadToArray ("c:\mytextfile") ; Full path to your text file with the 3 lines For $i = 0 To UBound ($filetext) - 1 $position = StringInStr ($filetext [$i], "KB",0,1) $aDateTime = StringRegExp ($filetext [$i], '\d{1,4}',3, $position + 2) _ArrayDisplay ($aDateTime) ;$aDateTime [0] - [2] are DD MM YYYY so code your if clause here Next ;-)) Stefan Link to comment Share on other sites More sharing options...
Malkey Posted July 28, 2009 Share Posted July 28, 2009 This is the type of situation I had envisaged the StringRegExpReplace callback function would be useful. ; #include <Date.au3> #cs ; Contents of "Test2.txt" is :- c:\Documents and Settings\ADMIN\Application Data\Microsoft\Internet Explorer\brndlog.bak 1 KB 13/01/2008 14:35:51 c:\Documents and Settings\ADMIN\Local Settings\Application Data\Microsoft\Internet Explorer\brndlog.bak 8 KB 13/10/2008 14:29:02 c:\Documents and Settings\administrateur\Application Data\Microsoft\Internet Explorer\brndlog.bak 1 KB 02/01/2008 14:35:51 ; Resulting MsgBox displays :- c:\Documents and Settings\ADMIN\Application Data\Microsoft\Internet Explorer\brndlog.bak 1 KB exceeds 2008/01/01 by 12 days c:\Documents and Settings\ADMIN\Local Settings\Application Data\Microsoft\Internet Explorer\brndlog.bak 8 KB exceeds 2008/01/01 by 286 days #ce Global $sMSG, $StartDate = "2008/01/01" Local $sFile = FileRead("Test2.txt") Local $sRetVar = StringRegExpReplace($sFile, "(.+?) (\d{2})/(\d{2})/(\d{4}) (\d{2}:\d{2}:\d{2})(\v+|$)", _ ' _CallFunction("\1","\2","\3","\4") & ') $sRetVar = Execute(StringTrimRight($sRetVar, 3)) MsgBox(64, "Results ", $sMSG) ; Display results Func _CallFunction($File, $d, $m, $y) ;ConsoleWrite($d & " " & $m & " " & $y & " " & @CRLF) Local $DateDiff = _DateDiff('D', $StartDate, $y & "/" & $m & "/" & $d) If $DateDiff >= 5 Then $sMSG &= $File & " exceeds " & $StartDate & " by " & $DateDiff & " days" & @CRLF EndIf Return 1 EndFunc ;==>_CallFunction ; 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