Open a specific folder and then Highlight (Select) the newest file or folder in it Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
HiSoKa
Posts: 480
Joined: 27 Jan 2020, 15:43

Open a specific folder and then Highlight (Select) the newest file or folder in it

27 Sep 2021, 01:06

Hello,
Is there way to Highlight (Select) the newest file in some folder,
I got this code bellow to show me which newest file, But in my case i need to open folder then highlight which newest in it not just show name in MsgBox ...

Code: Select all

 ;author: wooly_sammot
;https://autohotkey.com/board/topic/59408-get-the-newest-file-in-a-folder/
Folder = C:\Folder ; change this to the actual folder



Loop, %Folder%\*

{

     FileGetTime, Time, %A_LoopFileFullPath%, C

     If (Time > Time_Orig)

     {

          Time_Orig := Time

          File := A_LoopFileName

     }

}

MsgBox, Newest file in %Folder% is %File%

Return
Thanks in advance ..
User avatar
HiSoKa
Posts: 480
Joined: 27 Jan 2020, 15:43

Re: Open a specific folder and then Highlight (Select) the newest file or folder in it

27 Sep 2021, 03:30

This post solved my problem, Thank you @swagfag

viewtopic.php?f=76&t=63043&hilit=SHOpenFolderAndSelectItems

This code after modification.
Note: I know this code can be shortened, but anyway it does the job .

Code: Select all

; Open a specific folder and select the most recent file


Folder = C:\Users\HiSoKa\Downloads\ ; change this to the actual folder

Loop, %Folder%\*
	
{

     FileGetTime, Time, %A_LoopFileFullPath%, C

     If (Time > Time_Orig)

     {

          Time_Orig := Time

          File := A_LoopFileName

     }

}

MsgBox, Newest file in %Folder% is %File%
FullLoc = %Folder%%File%


MyPath := % FullLoc
OpenAndSelect(MyPath)
return

OpenAndSelect(sFullPath)
{
	SplitPath sFullPath, , sPath
	FolderPidl := DllCall("shell32\ILCreateFromPath", "Str", sPath)
	DllCall("shell32\SHParseDisplayName", "str", sFullPath, "Ptr", 0, "Ptr*", ItemPidl, "Uint", 0, "Uint*", 0)
	DllCall("shell32\SHOpenFolderAndSelectItems", "Ptr", FolderPidl, "UInt", 1, "Ptr*", ItemPidl, "Int", 0)
	CoTaskMemFree(FolderPidl)
	CoTaskMemFree(ItemPidl)
}

CoTaskMemFree(pv)
{
	Return   DllCall("ole32\CoTaskMemFree", "Ptr", pv)
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Joey5, mcd, NullRefEx and 125 guests