Autohotkey 监视文件夹中的新文件

Autohotkey 监视文件夹中的新文件

我正在尝试观察文件夹中是否有新的变化,然后执行按键操作。

以下是我目前所掌握的信息:

#j::
Loop 5
{

    Send ^!{c}
    ; watch and wait folder path until a new file is added
    Send {down}
}
return

我不确定如何解决这个问题,有什么帮助吗?

答案1

#j::
IfWinActive, ahk_class CabinetWClass
{
 SetTitleMatchMode, 3
 WinGetTitle, active_title, A
 for window in ComObjCreate("Shell.Application").Windows
 try address := % window.Document.Folder.Self.Path   ; http://ahkscript.org/boards/viewtopic.php?p=28751#p28751
 ; MsgBox, "%address%"
 SetTimer, FileAdded, 500
}
return

FileAdded:
Loop, %address%\*.*
{
 now := %A_Now%
 EnvSub, now, %A_LoopFileTimeCreated%, seconds
 If now < 2 ; newer as 2 seconds
 { 
  SetTimer, FileAdded, off
  ; MsgBox a new file `n%A_LoopFileFullPath% `nis added in %address%
  ; Run, %address%  ; if the explorer window has been closed in the meantime
  WinWait, %active_title% 
  WinActivate, %active_title% 
  WinWaitActive, %active_title%
  ; Send, your keys
  ; Sleep some time
  ; SetTimer, FileAdded, on
 }
}
return

相关内容