Ahk脚本在当前文件夹中找到最新更改的文件或文件夹?

问题描述 投票:1回答:1

我经常将文件从Chrome保存到Downloads文件夹或My Documents文件夹。您必须稍后在该文件夹中查找这些文件。告诉我是否有可能以某种方式使用ahk脚本更方便。例如,按F3键,将突出显示当前文件夹中的最后一个文件或文件夹。如何实现它。请帮帮我,我是新人

autohotkey hotkeys
1个回答
0
投票
F3::
    SetTitleMatchMode, 2
    File := "" ; empty variable
    Time := ""
    Loop, Files, %A_MyDocuments%\Downloads\*.*, DF ; include files and folders
    {
        If (A_LoopFileTimeModified >= Time)
        {
            Time := A_LoopFileTimeModified        ; the time the file/folder was last modified
            File := A_LoopFileFullPath            ; the path and name of the file/folder currently retrieved
        }
    }
    ; MsgBox, Last modified file in %A_MyDocuments%\Downloads is`n`n"%File%"
    IfWinNotExist Downloads ahk_class CabinetWClass
        Run % "explorer.exe /select," . File      ; open containing folder and highlight this file/folder
    else
    {
        SplitPath, File, name
        MsgBox, Last modified file = "%name%"
        WinActivate, Downloads ahk_class CabinetWClass
        WinWaitActive, Downloads ahk_class CabinetWClass
        ; SelectExplorerItem(name) ; or:
        SendInput, %name%
    }
    return

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
   Window := ""
   Static Shell := ComObjCreate("Shell.Application")
   For Window In Shell.Windows
    try  IfWinActive, % "ahk_id " window.HWND
         If (Item := Window.Document.Folder.ParseName(ItemName))
            Window.Document.SelectItem(Item, 29)
   Return (Item ? True : False)
}

https://autohotkey.com/docs/commands/LoopFile.htm

© www.soinside.com 2019 - 2024. All rights reserved.