简体   繁体   English

当文件出现在目录中时,如何在 tcl 中自动运行脚本?

[英]How to run a script automatically in tcl when a file appears in a directory?

I have a script ready in tcl to run but till now i am doing it manually because i have to wait for some file generation to complete.我在 tcl 中有一个准备好运行的脚本,但直到现在我都是手动执行的,因为我必须等待一些文件生成完成。

How to automate this process that if a file appears, tcl script should trigger automatically?如何自动化这个过程,如果一个文件出现,tcl脚本应该自动触发?

Assuming there are normally zero files in the watched directory, this is an efficient way to poll the directory periodically:假设监视目录中通常有零个文件,这是定期轮询目录的有效方法:

proc waitForFiles {directory} {
    set files [glob -directory $directory -nocomplain]
    if {[llength $files] == 0} {
        doSomethingHere
    }
    # check again in 100 milliseconds
    after 100 [list waitForFiles $directory]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM