Hi,
How can I find the newest txt file in an folder.
with Loop, Files, c:\tmp\*.txt the files are not in the right order that I need.
So, how can I do to have the newest txt file from the folder ?
Surely something with A_LoopFileTimeAccessed. But I don't know how to do it.
Maybe in an array and sort it?
Find newest txt file in directory
-
- Posts: 175
- Joined: 15 Dec 2016, 04:27
Re: Find newest txt file in directory
This isn't pretty but it works
Code: Select all
AccessedArray := []
Loop, Files, c:\tmp\*.txt
{
Accessed .= A_LoopFileTimeAccessed "`n"
AccessedArray[A_LoopFileTimeAccessed] := A_LoopFileFullPath
}
Sort, Accessed,N
Loop, Parse,Accessed,`n
output .= AccessedArray[A_LoopField] "`n"
msgbox, % output
-
- Posts: 175
- Joined: 15 Dec 2016, 04:27
Re: Find newest txt file in directory
Here it is a bit fancier.
Code: Select all
AccessedArray := []
Loop, Files, c:\tmp\*.txt
{
FormatTime, Formattedtime,A_LoopFileTimeAccessed, MM/dd/yy 'at' hh:mm:ss tt
Accessed .= A_LoopFileTimeAccessed "`n"
AccessedArray[A_LoopFileTimeAccessed] := A_LoopFileFullPath " was last accessed on " Formattedtime
}
Sort, Accessed,NR backwards
Loop, Parse,Accessed,`n
output .= AccessedArray[A_LoopField] "`n"
msgbox, % output
Re: Find newest txt file in directory
How can I find the newest txt file in an folder.
Code: Select all
LastAccess := 0
Loop, Files, c:\tmp\*.txt
{
If (A_LoopFileTimeAccessed > LastAccess) {
LastAccess := A_LoopFileTimeAccessed
NewestFile := A_LoopFileLongPath
}
}
MsgBox, %NewestFile%
Re: Find newest txt file in directory
Thanks "ManualColdLock" and "just me".
I've taken the version of "just me" because it's smaller
I've taken the version of "just me" because it's smaller
Re: Find newest txt file in directory
I would check for A_LoopFileTimeModified rather than
A_LoopFileTimeAccessed, just thought that someone should mention that!
A_LoopFileTimeAccessed, just thought that someone should mention that!
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: Find newest txt file in directory
@jeeswg
already done but didn't mention it
Thanks for the reminder.
already done but didn't mention it
Thanks for the reminder.
Re: Find newest txt file in directory
Hahaha cool. Thanks for letting me know.
[EDIT:]
Btw for C:\Users\%A_UserName%\Pictures,
I would use A_LoopFileTimeCreated,
because when you save an image via Internet Explorer,
I believe the modified date is the date the image was downloaded to IE's cache,
whereas the created date is the date when you saved the file.
Also I often skip these files when listing files in a folder:
if (vName = "desktop.ini") OR (vName = "Thumbs.db")
continue
[EDIT:]
Btw for C:\Users\%A_UserName%\Pictures,
I would use A_LoopFileTimeCreated,
because when you save an image via Internet Explorer,
I believe the modified date is the date the image was downloaded to IE's cache,
whereas the created date is the date when you saved the file.
Also I often skip these files when listing files in a folder:
if (vName = "desktop.ini") OR (vName = "Thumbs.db")
continue
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
- Almost_there
- Posts: 404
- Joined: 30 Sep 2014, 10:32
Re: Find newest txt file in directory
The "created date" is the time when the file was created (obvious). It differs from "modified date" in the way that it doesn't change when file is overwritten (i.e. you open a file in an editor and hit Save).
Also - if you copy the file to an new location - the "created date" will be set to the time the new copy was made.
Also - if you copy the file to an new location - the "created date" will be set to the time the new copy was made.
Re: Find newest txt file in directory
For me I want the newest file. Non depending of wich time is taken.
So something like a 'ls -lrt' in unix.
This is why I think that the modified time suit my need.
But if anyone have a better/safer way for finding the newer file.
But my need is not so 'complicated' because I need to open that file from 'lotus notes', so it will always be here and at least 5 seconds ago.
So something like a 'ls -lrt' in unix.
This is why I think that the modified time suit my need.
But if anyone have a better/safer way for finding the newer file.
But my need is not so 'complicated' because I need to open that file from 'lotus notes', so it will always be here and at least 5 seconds ago.
Who is online
Users browsing this forum: FanaticGuru, Google [Bot], Jaroz and 135 guests