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

时间:2019-02-14 06:34:58

标签: autohotkey hotkeys

我经常将文件从Chrome保存到“下载”文件夹或“我的文档”文件夹中。 您稍后必须在文件夹中查找这些文件。告诉我使用ahk脚本是否可能使它更方便。例如,通过按F3键,突出显示当前文件夹中的最后一个文件或文件夹。如何实施。请帮助我,我是新来的

1 个答案:

答案 0 :(得分: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