[SOLVED] SSD disk + log file (modify last access time)

Get help with using AutoHotkey and its commands and hotkeys
User avatar
Peace1
Posts: 41
Joined: 17 Mar 2015, 14:19
Location: 127.0.0.1

[SOLVED] SSD disk + log file (modify last access time)

24 Mar 2015, 13:15

Hi all,

Well I ask for help because I didn't find anything similar on the forum.

I wrote a script that reads the x last lines of a log file and a function that checks the last file modification time but my problem is that with an SSD hard drive the modify last access time (of log file) happen if I open the log file with notepad for example.

So my question is how I can solve this problem please ?

Here is the snippet code

Code: Select all

FileSelectFile, SelectedFileLog, 3, %A_WorkingDir%\task_log\, Open a file, Log File (*.log)
LogFile := SelectedFileLog
LogLast := ReadLog(20, LogFile)

ReadLog(k,file)   ; Return the last k lines of file
{
   Loop Read, %file%
   {
      i := Mod(A_Index,k)
      L%i% = %A_LoopReadLine%
   }
   L := L%i%
   Loop % k-1
   {
      IfLess i,1, SetEnv i,%k%
      i--      ; Mod does not work here
      L := L%i% "`n" L
   }
   Return L
}

ScanFile()
{
    global
    FileGetTime, previoustime, %LogFile%
    SetTimer, check_time, 100

    check_time: 
    FileGetTime, time, %LogFile%
    If (time != previoustime) 
    {
        MsgBox, File was modified !
        previoustime := time
    } 
    return
}
Thank you in advance for the help.

Best regards.
Last edited by Peace1 on 26 Mar 2015, 15:26, edited 1 time in total.
User avatar
LinearSpoon
Posts: 156
Joined: 29 Sep 2013, 22:55

Re: [HELP] SSD disk + log file (modify last access time)

24 Mar 2015, 17:47

I am unable to replicate this by simply opening the file. I have tested when the file was on an SSD and a "classic" hard drive, opening with Notepad, Notepad++, Visual Studio, SciTE4AutoHotkey, and HxD. Is it possible the program that creates the log file is updating it?

You might want to post more details, such as what you expect AutoHotkey should do about this. It has no control over when Notepad or any other program updates the file modified time.
lexikos
Posts: 7141
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: [HELP] SSD disk + log file (modify last access time)

24 Mar 2015, 21:56

Peace1 wrote:last file modification time [...] last access time
N.B. These are two different things. Your script gets the last modified time, not the last access time. Merely viewing the file's properties in Explorer can bump the last access time. Opening a file in Notepad will not change the last modified time; only saving it will.
User avatar
Peace1
Posts: 41
Joined: 17 Mar 2015, 14:19
Location: 127.0.0.1

Re: [HELP] SSD disk + log file (modify last access time)

25 Mar 2015, 03:21

LinearSpoon wrote:I am unable to replicate this by simply opening the file. I have tested when the file was on an SSD and a "classic" hard drive, opening with Notepad, Notepad++, Visual Studio, SciTE4AutoHotkey, and HxD. Is it possible the program that creates the log file is updating it?

You might want to post more details, such as what you expect AutoHotkey should do about this. It has no control over when Notepad or any other program updates the file modified time.
Hi LinearSpoon,

First thank you to take the time to do all your tests !

And yes I forget to mention it but the program who create the log file it update it constantly.

If I open the log manually my explorer show the good last time modified but if I don't open it manually the time doesn't change automatically...

Here is a piece of the log for example : http://ahkscript.org/boards/viewtopic.php?f=5&t=6765

Thank you in advance for your help and time.

Best regards.

Sent from my smartphone.
User avatar
Peace1
Posts: 41
Joined: 17 Mar 2015, 14:19
Location: 127.0.0.1

Re: [HELP] SSD disk + log file (modify last access time)

26 Mar 2015, 15:25

Hi all !

Well i fixed my problem with the read a the log file.

My principal mistake was the function of loop read. If some person is interested here is the new good function :

Code: Select all

Tail(k,file)   ; Return the last k lines of file
{
   FileRead text, %file%
   Loop Parse, text, `n
     lines++
   Loop Parse, text, `n
   {
      If (A_Index < lines - k)
         Continue
      L = %L%`n%A_Loopfield%
   }
   StringTrimLeft L, L, 1
   Return L
}
Credits to the author Laszlo ==> http://www.autohotkey.com/board/topic/6 ... entry38875

BTW thank you for all, regards.
just me
Posts: 7718
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [SOLVED] SSD disk + log file (modify last access time)

27 Mar 2015, 03:18

A good example from the good old times. But it will have poor performance if your log file will grow large.

You might want to try this one instead:

Code: Select all

FileGetAddedLines(File, ReturnWholeFileOnFirstCall := False) {
   Static BytesReadPerFile := {}
   If !(HFILE := FileOpen(File, "r"))
      Return ""
   If !BytesReadPerFile.HasKey(File) {
      BytesReadPerFile[File] := ReturnWholeFileOnFirstCall ? 0 : HFILE.Length
      If !(ReturnWholeFileOnFirstCall)
         Return ""
   }
   BytesRead := BytesReadPerFile[File]
   If (HFILE.Length = BytesRead)
      Return ""
   HFILE.Pos := HFILE.Length < BytesRead ? 0 : BytesRead
   AddedLines := HFILE.Read()
   BytesReadPerFile[File] := HFILE.Length
   Return AddedLines
}
User avatar
Peace1
Posts: 41
Joined: 17 Mar 2015, 14:19
Location: 127.0.0.1

Re: [SOLVED] SSD disk + log file (modify last access time)

27 Mar 2015, 06:01

Hi just me,

Thank you for your help ! I'm agree with you this is a little old code and for small log file...

ATM I'm at office work so I can't test your code but when I back to home I will try it ASAP :)

I'm sure your code is better and faster ^^

Best regards !

Edit: Well i tested your code but the problem is that don't work like i want with this function in my script.
With your code my msgbox Data not found into the LOG file ! pop after the second read loop. Perhaps you can find the way to fix it ?!

Code: Select all

FindString()
{
    global
    ;Function to read the LOG file
    LogLast := ReadLog(20, LogFile)
    ifinstring, LogLast, =>
    {
        Loop, parse, LogLast, `n, `r
            If InStr(A_LoopField, "=>")
                lastline := A_LoopField
 
        ;MsgBox % lastline ; just checking as test
 
        DesiredString := StrSplit(RegExReplace(lastline,"^.*\]\s*(.*) => (.*)","$1|$2"),"|")
        DesiredString1 := DesiredString[1]
        DesiredString2 := DesiredString[2]
        ;MsgBox, % DesiredString[1]
        ;MsgBox, % DesiredString[2]
    }
    IfNotInString, LogLast, =>
    {
        MsgBox, 16,, Data not found into the LOG file !
        gosub, StopIndicator
    }
}

Code: Select all

18:03:35:INFO:: = [0]  action planned >>>>>>>
18:03:35:INFO:: = [0]  Execute task1 :this is a test[2/2]
18:03:35:INFO:: = [0]   Launch this program now => The program was launched
18:03:35:INFO:: = [0]  action paused, click [Continue] to resume, or [Reload] to reload.
18:03:44:INFO:: = [0]  action resumed.
18:03:49:INFO:: = [0]  no action rules matched.
18:03:49:INFO:: = [0]  action planned >>>>>>>
18:03:49:INFO:: = [0]  Execute task2 :this is a test[3/4]
18:03:49:INFO:: = [0]   Reload the program => The program was reloaded
18:03:49:INFO:: = [0]  action paused, click [Continue] to resume, or [Reload] to reload.
18:04:02:INFO:: = [0]  action resumed.
Regards.

Return to “Ask For Help”

Who is online

Users browsing this forum: Bar_Dres, Bing [Bot], Spawnova, XMCQCX, yh0099 and 46 guests