Select Most Recent File in a Folder Topic is solved
Select Most Recent File in a Folder
I'm trying to rename a file a specific file ( which I know how to do ) but having trouble figuring out how to select the file path of the most recent file in a given folder. How do I do this?
-
- Posts: 1472
- Joined: 05 May 2018, 12:23
Re: Select Most Recent File in a Folder
By @SKAN https://autohotkey.com/board/topic/59408-get-the-newest-file-in-a-folder/
Code: Select all
Loop %A_WinDir%\*.*
If ( A_LoopFileTimeModified >= Time )
Time := A_LoopFileTimeModified, File := A_LoopFileLongPath
MsgBox, Lastest file in %A_WinDir% is `n`n%File%
Re: Select Most Recent File in a Folder
@AHKStudent
Do you know what I'm doing wrong here? Here I keep on getting the most recent file is C:\windows\bootstat.dat.
Do you know what I'm doing wrong here? Here I keep on getting the most recent file is C:\windows\bootstat.dat.
Code: Select all
^o::
A_WinDR := "C:\Users\myname\Desktop\foldername\subfoldername"
Loop %A_WinDir%\*.*
If ( A_LoopFileTimeModified >= Time )
Time := A_LoopFileTimeModified, File := A_LoopFileLongPath
MsgBox, Lastest file in %A_WinDir% is `n`n%File%
Return
Re: Select Most Recent File in a Folder
from the docu:
HubertBuilt-in Variables
A number of useful variables are built into the program and can be referenced by any script. With the exception of Clipboard, ErrorLevel, and command line parameters, these variables are read-only; that is, their contents cannot be directly altered by the script.
-
- Posts: 1472
- Joined: 05 May 2018, 12:23
Re: Select Most Recent File in a Folder
maybe its a hidden file in that directory that is the most recent.3ggg wrote: ↑26 Nov 2019, 02:07@AHKStudent
Do you know what I'm doing wrong here? Here I keep on getting the most recent file is C:\windows\bootstat.dat.
Code: Select all
^o:: A_WinDR := "C:\Users\myname\Desktop\foldername\subfoldername" Loop %A_WinDir%\*.* If ( A_LoopFileTimeModified >= Time ) Time := A_LoopFileTimeModified, File := A_LoopFileLongPath MsgBox, Lastest file in %A_WinDir% is `n`n%File% Return
Try copying and pasting something new to that directory and run it again.
Re: Select Most Recent File in a Folder
Code: Select all
Loop %A_WinDR%\*.*
Re: Select Most Recent File in a Folder
@AHKStudent
tried with multiple different folders, moving things around, still got that boot.stat thing every time. I'm sure I'm getting something wrong
tried with multiple different folders, moving things around, still got that boot.stat thing every time. I'm sure I'm getting something wrong
Re: Select Most Recent File in a Folder Topic is solved
@3ggg
There are at least two problems:
* A typo. You have A_WinDR (it seems you mean A_WinDir)
* You can't use A_WinDir (or any another built-in variable) as an output variable.
And by the way, the name like WinDir is just misleading here, to my opinion. I changed it to Foo.
There are at least two problems:
* A typo. You have A_WinDR (it seems you mean A_WinDir)
* You can't use A_WinDir (or any another built-in variable) as an output variable.
And by the way, the name like WinDir is just misleading here, to my opinion. I changed it to Foo.
Code: Select all
^o::
Foo := A_Desktop . "\Test" ; C:\Users\John\Desktop\Test
Loop %Foo%\*.*
If ( A_LoopFileTimeModified >= Time )
Time := A_LoopFileTimeModified, File := A_LoopFileLongPath
MsgBox, Lastest file in %Foo% is `n`n%File%
Return
Who is online
Users browsing this forum: inseption86, mikeyww and 456 guests