I am still very new to using AHK and I have a script I want to modify that I need help with. I have a script that I am using to show the contents of a .csv file in a GUI window. It currently reads the newest .csv file in the referenced folder location. It displays the header row and the last five rows of the file which works perfect for the application I developed it for. However, I am now needing to have a display window that will read the five newest .csv files in a specified folder and display their contents similar to the script I have here (except instead of the last five lines in one file, I want the contents of the last five files to show sequentially in the window). I have two thoughts on how to do this, but I am not sure how to accomplish either. Any help would be greatly appreciated!
Option 1: Have the script determine the five newest files in the folder and display their contents in the GUI with the GUI window fixed in size like the current one and it will just scroll through the contents of each file in order (oldest on top, newest on bottom), with the screen updating every 5s.
Option 2: Create a separate .csv file (in a different folder) that contains the appended contents of the five newest .csv files, then use the script I already have to read that file except have it show all the lines in the file and not just the last five lines (need to know how to do that as well).
Here is the script I have to start with:
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#Persistent
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance force
Newest := 0
NewestFile := ""
Gui, +AlwaysOnTop
Gui, font, S20 Arial Bold
Gui, add, edit, w500 r6 vLast5
Gui, show
SetTimer, ReadCSV, 5000 ; 5 seconds, adjust timer frequency as you wish
return
GuiClose:
ExitApp
return
ReadCSV:
Folder = C:\My Documents ; target folder for file
Loop, %Folder%\Scan Log*.csv
{
if (A_LoopFileTimeCreated > Newest) { ;if this file is newer continue
Newest := A_LoopFileTimeCreated ;reset variable to higher value
NewestFile := A_LoopFileLongPath ;reset varaible to newest file
}
}
CopyToFile := NewestFile
FileRead, data, %CopyToFile%
data := Trim(data, "`r`n")
line := StrSplit(data, "`n", "`r")
result := line[1]
. (line.MaxIndex()>5 ? "`r`n" line[line.MaxIndex()-4] : "")
. (line.MaxIndex()>4 ? "`r`n" line[line.MaxIndex()-3] : "")
. (line.MaxIndex()>3 ? "`r`n" line[line.MaxIndex()-2] : "")
. (line.MaxIndex()>2 ? "`r`n" line[line.MaxIndex()-1] : "")
. (line.MaxIndex()>1 ? "`r`n" line[line.MaxIndex()] : "")
GuiControl,, Last5, % result
return
Thanks!
Chris70