我有以下代码,据我所知,它应该可以工作。目标是不断检查 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/