About FileGetTime

Get help with using AutoHotkey and its commands and hotkeys
Marcosa1020
Posts: 160
Joined: 23 Sep 2015, 19:15

About FileGetTime

04 Dec 2019, 01:06

Hello,

I have a question need your help. Program_A can search all files in the the folder(G:\Download\).
Due to search long time, I want to search for files in five months, so I added the code as below in program_B.
Then as you can see, it is incomplete. How can I to control this search in five months ?
I will appreciate your help with this situation.

Code: Select all

FormatTime, TimeString,,yyyy/mm/dd   ;<<<<<<<<<<<<<<<<<<<<<<<
FileGetTime, DateTime, G:\Download\Paper_A.txt, C ;<<<<<<<<<<<<
If DateTime < ??? ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Program_A:

Code: Select all

SetBatchLines, -1
LoadData_GroupA("G:\Download\")
LoadData_GroupA(Folder) {
	objA := {}
	Loop, Files, % Folder . "\Paper_A.txt*.log"
	{
		FileRead, data, %A_LoopFileFullPath%

		r := "`s)\R\((?P<date>\d{2}/\d{2}/\d{2}:\d{2}.\d{2})[^\r\n]+\R+"
		   . "BTP (?P<num>\d+)"
		   . ".*?\R+    (?P<temp>[\d.+-]+)"
		
		startPos := 1
		while foundPos := RegExMatch(data, r, m_, startPos) {
			m_date := RegExReplace(m_date, "^(.{5})/(..)(.*)$", "$2/$1/$3")
			if (m_date > objA[m_num]["date"]) {
				objA[m_num] := {date: m_date, temp: m_temp}
			}
			startPos := foundPos + StrLen(m_)
		}
	}

	for n, ctrlId in {Level_1:"card1", Level_2:"card2", Level_3:"card3", Level_4:"card4"} {
		GuiControl,, % ctrlId, % objA[n].temp
	}
Program_B:

Code: Select all

SetBatchLines, -1
LoadData_GroupA("G:\Download\")
LoadData_GroupA(Folder) {
	objA := {}
FormatTime, TimeString,,yyyy/mm/dd   ;<<<<<<<<<<<<<<<<<<<<<<<
FileGetTime, DateTime, G:\Download\Paper_A.txt, C ;<<<<<<<<<<<<
If DateTime < ??? ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
	Loop, Files, % Folder . "\Paper_A.txt*.log"
	{
		FileRead, data, %A_LoopFileFullPath%

		r := "`s)\R\((?P<date>\d{2}/\d{2}/\d{2}:\d{2}.\d{2})[^\r\n]+\R+"
		   . "BTP (?P<num>\d+)"
		   . ".*?\R+    (?P<temp>[\d.+-]+)"
		
		startPos := 1
		while foundPos := RegExMatch(data, r, m_, startPos) {
			m_date := RegExReplace(m_date, "^(.{5})/(..)(.*)$", "$2/$1/$3")
			if (m_date > objA[m_num]["date"]) {
				objA[m_num] := {date: m_date, temp: m_temp}
			}
			startPos := foundPos + StrLen(m_)
		}
	}

	for n, ctrlId in {Level_1:"card1", Level_2:"card2", Level_3:"card3", Level_4:"card4"} {
		GuiControl,, % ctrlId, % objA[n].temp
	}
rakesha002
Posts: 34
Joined: 04 Dec 2017, 00:11

Re: About FileGetTime

05 Dec 2019, 09:11

HI,
I think you want this,

Code: Select all

SetBatchLines, -1
Searchpath := "G:\Download\", RefFile := "G:\Download\Paper_A.txt"
LoadData_GroupA(Searchpath, RefFile)


LoadData_GroupA(Folder, RFile) {
	objA := {}
	FileGetTime, DateTime, %RFile%, C ;<<<<<<<<<<<<		this is the reference file right?
	Loop, Files, % Folder . "\Paper_A.txt*.log"
	{
		DateTime1 := DateTime
		EnvSub, DateTime1, A_LoopFileTimeCreated, D
		if (DateTime1 > 150) {			;	use < for older files and > for newer files (30days x 5months = 150)
			FileRead, data, %A_LoopFileFullPath%

			r := "`s)\R\((?P<date>\d{2}/\d{2}/\d{2}:\d{2}.\d{2})[^\r\n]+\R+"
			   . "BTP (?P<num>\d+)"
			   . ".*?\R+    (?P<temp>[\d.+-]+)"
			
			startPos := 1
			while foundPos := RegExMatch(data, r, m_, startPos) {
				m_date := RegExReplace(m_date, "^(.{5})/(..)(.*)$", "$2/$1/$3")
				if (m_date > objA[m_num]["date"]) {
					objA[m_num] := {date: m_date, temp: m_temp}
				}
				startPos := foundPos + StrLen(m_)
			}

			for n, ctrlId in {Level_1:"card1", Level_2:"card2", Level_3:"card3", Level_4:"card4"} {
				GuiControl,, % ctrlId, % objA[n].temp
			}
		}
	}
}
Hope this helps
Marcosa1020
Posts: 160
Joined: 23 Sep 2015, 19:15

Re: About FileGetTime

06 Dec 2019, 08:25

rakesha002 wrote:
05 Dec 2019, 09:11
HI,
I think you want this,

Code: Select all

SetBatchLines, -1
Searchpath := "G:\Download\", RefFile := "G:\Download\Paper_A.txt"
LoadData_GroupA(Searchpath, RefFile)


LoadData_GroupA(Folder, RFile) {
	objA := {}
	FileGetTime, DateTime, %RFile%, C ;<<<<<<<<<<<<		this is the reference file right?
	Loop, Files, % Folder . "\Paper_A.txt*.log"
	{
		DateTime1 := DateTime
		EnvSub, DateTime1, A_LoopFileTimeCreated, D
		if (DateTime1 > 150) {			;	use < for older files and > for newer files (30days x 5months = 150)
			FileRead, data, %A_LoopFileFullPath%

			r := "`s)\R\((?P<date>\d{2}/\d{2}/\d{2}:\d{2}.\d{2})[^\r\n]+\R+"
			   . "BTP (?P<num>\d+)"
			   . ".*?\R+    (?P<temp>[\d.+-]+)"
			
			startPos := 1
			while foundPos := RegExMatch(data, r, m_, startPos) {
				m_date := RegExReplace(m_date, "^(.{5})/(..)(.*)$", "$2/$1/$3")
				if (m_date > objA[m_num]["date"]) {
					objA[m_num] := {date: m_date, temp: m_temp}
				}
				startPos := foundPos + StrLen(m_)
			}

			for n, ctrlId in {Level_1:"card1", Level_2:"card2", Level_3:"card3", Level_4:"card4"} {
				GuiControl,, % ctrlId, % objA[n].temp
			}
		}
	}
}
Hope this helps
Hi,
I need some time to test the code. Thank you for your reply.

Return to “Ask For Help”

Who is online

Users browsing this forum: CarPiotr, Herchi and 52 guests