autohotkey - 当文件开始存在时如何使用自动热键对其进行操作?

标签 autohotkey

我有以下代码,据我所知,它应该可以工作。目标是不断检查 Z:\auto_run.txt 是否存在。一旦存在,文件的每一行(作为文件的路径)都应该在 Notepad++ 中打开。最后删除Z:\auto_run.txt。

我最后一次独立工作了。问题是如何不断检查文件是否存在?当我在标准 Autohotkey.ahk 中运行以下代码时,它似乎不起作用,即使文件存在,也没有任何反应。

IfExist, Z:\auto_run.txt
{
    Loop, read, Z:\auto_run.txt
    {
        IfExist, Z:\%A_LoopReadLine%
            Run, C:\Program Files (x86)\Notepad++\notepad++.exe Z:\%A_LoopReadLine%
    }
    FileDelete, Z:\autohotkey\auto_run.txt
}

最佳答案

将整个事情放入循环中可以吗?

Loop
{
    IfExist, Z:\auto_run.txt
    {
        Loop, read, Z:\auto_run.txt
        {
            IfExist, Z:\%A_LoopReadLine%
                Run, C:\Program Files (x86)\Notepad++\notepad++.exe Z:\%A_LoopReadLine%
        }
        FileDelete, Z:\autohotkey\auto_run.txt
    }

    Sleep, 100 ; Short sleep
}

如果您不想将脚本锁定到循环,您也可以使用计时器。

#Persistent

fullFilePath := "Path\To\File.txt"
SetTimer, CheckForFile, 500
return

CheckForFile:
    if (FileExist(fullFilePath)) {
        ; Do something with the file...
        Loop, Read, %fullFilePath%
        {
            MsgBox % A_LoopReadLine
        }

        ; Delete the file
        FileDelete, %fullFilePath%
    }
return

关于autohotkey - 当文件开始存在时如何使用自动热键对其进行操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31034959/

相关文章:

email - 如何将参数传递给 .msg 文件?

mouse - AutoHotkey 按下按钮将光标向左 move

autohotkey - 使用 AutoHotkey 记录多个按键

gmail - 需要通过 SMTP 和 Autohotkey 发送电子邮件 (gmail)。

autohotkey - 如何在 autohotkey 中重新映射 alt+tab?

Autohotkey:代码块注释和取消注释热键

windows-10 - 如何在AutoHotKey中启动Windows Store应用程序?

html - 创建一个脚本来填写表单值并提交

autohotkey - 使用自动热键在 Notepad++ 中模仿 Sublime Text 2 多选(多光标)

autohotkey - 使用 GetKeyState 创建 3 键热键,而不触发另一个类似的 2 键热键