Could someone please help me with a script to delete the last file in the directory
C:\Users\crowe\OneDrive\Pictures\Screenshots when I press {F9}?
Thank you.
Script Help: Delete Last File on F9 Press
Re: Script Help: Delete Last File on F9 Press
Hello,
How is "last file" defined?
How is "last file" defined?
Re: Script Help: Delete Last File on F9 Press
For example, I clicked "win + printscreen" to take a screenshot of the screen:
printscreen01.png
printscreen02.png
printscreen03.png
And then I press {F9} so that I can find the last file to delete, which would be printscreen03.png
Got it?
Re: Script Help: Delete Last File on F9 Press
Are you referring to the file that is last in alphanumeric order by filename?
Re: Script Help: Delete Last File on F9 Press
Wouldn't it be a good idea to use Loop Files to obtain the file path with the most recent A_LoopFileTimeCreated value?
(Anyway, I'm just realizing now that screenshots are being saved to OneDrive...)
(Anyway, I'm just realizing now that screenshots are being saved to OneDrive...)
- English is not my native language. Please forgive any awkward expressions.
- 영어는 제 모국어가 아닙니다. 어색한 표현이 있어도 양해해 주세요.
Re: Script Help: Delete Last File on F9 Press
Code: Select all
#Requires AutoHotkey v2.0
F9:: {
Static shotsDir := StrReplace(A_Desktop, 'Desktop', 'Pictures\Screenshots')
If FileExist(newest := getNewestFile(shotsDir)) {
FileRecycle newest
MsgBox 'Deleted:`n`n' newest, 'Status', 'Iconi'
} Else MsgBox 'Nothing was deleted.', 'Warning', 'Icon!'
}
getNewestFile(dir) {
time := 0
Loop Files dir '\*.*'
If A_LoopFileTimeCreated > time {
time := A_LoopFileTimeCreated
fPath := A_LoopFilePath
}
Return fPath ?? ''
}
Re: Script Help: Delete Last File on F9 Press
I got error:mikeyww wrote: ↑06 May 2024, 11:21Code: Select all
#Requires AutoHotkey v2.0 F9:: { Static shotsDir := StrReplace(A_Desktop, 'Desktop', 'Pictures\Screenshots') If FileExist(newest := getNewestFile(shotsDir)) { FileRecycle newest MsgBox 'Deleted:`n`n' newest, 'Status', 'Iconi' } Else MsgBox 'Nothing was deleted.', 'Warning', 'Icon!' } getNewestFile(dir) { time := 0 Loop Files dir '\*.*' If A_LoopFileTimeCreated > time { time := A_LoopFileTimeCreated fPath := A_LoopFilePath } Return fPath ?? '' }
Re: Script Help: Delete Last File on F9 Press
Use the latest version posted.
Who is online
Users browsing this forum: Bing [Bot] and 35 guests