答案1
尝试这个 AHK 脚本:
; Press F1 in the active explorer window to jump to the last folder in the folder-file-list
#IfWinActive ahk_class CabinetWClass ; Explorer
F1::
last_folder := ""
ExplorerPath := GetActiveExplorerPath()
Loop, Files, %ExplorerPath%\*, D ; only folders
last_folder := A_LoopFileName
If (last_folder = "")
MsgBox, No folders in`n%A_Tab%"%ExplorerPath%"
else
SelectExplorerItem(last_folder)
return
#IfWinActive
GetActiveExplorerPath() { ; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=69925
explorerHwnd := WinActive("ahk_class CabinetWClass")
if (explorerHwnd)
{
for window in ComObjCreate("Shell.Application").Windows
{
if (window.hwnd==explorerHwnd)
{
return window.Document.Folder.Self.Path
}
}
}
}
SelectExplorerItem(ItemName) { ; selects the specified item in the active explorer window, if present
; SelectItem -> msdn.microsoft.com/en-us/library/bb774047(v=vs.85).aspx
explorerHwnd := ""
explorerHwnd := WinActive("ahk_class CabinetWClass")
if (explorerHwnd)
{
for window in ComObjCreate("Shell.Application").Windows
{
try if (window.hwnd==explorerHwnd)
{
If (Item := Window.Document.Folder.ParseName(ItemName))
Window.Document.SelectItem(Item, 29)
Return (Item ? True : False)
}
}
}
}
答案2
为了获取最后一个文件夹,无论文件的排序顺序如何(只要文件夹在前面),我建议采用简单的方法,即沿着列表中的项目向下移动并在最后一个文件夹上停下。
此 AutoHotKey 脚本将使用热键执行此操作F10:
#IfWinActive, ahk_class CabinetWClass
F10::
Send, {Home}
Sleep, 5
last=
loop {
file = % Explorer_GetSelection()
isfolder = % InStr(FileExist(file),"D")
if !isfolder or file==last
break
last = % file
Send, {Down}
Sleep, 5
}
if !isfolder
Send, {Up}
Explorer_GetSelection(hwnd="") {
hwnd := hwnd ? hwnd : WinExist("A")
WinGetClass class, ahk_id %hwnd%
for window in ComObjCreate("Shell.Application").Windows
if (window.hwnd==hwnd)
sel := window.Document.SelectedItems
for item in sel
ToReturn .= item.path "`n"
return Trim(ToReturn,"`n")
}
安装 AutoHotKey 后,将上述文本放入一个.ahk
文件中并双击进行测试。您可以通过右键单击托盘栏中的绿色 H 图标并选择退出来停止脚本。要让它在登录时运行,请将其放在 的启动组中
C:\Users\USER-NAME\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
。
有用的 AutoHotkey 文档: