Check if File not exist within a rule

Hello,

i want to check if a file not exists within a rule or with other words the rule should only run when a special file not exists. With this i will be sure that a rule will not be triggert in very short time twice.
Please give me a sample openhab2 rule code
Thamk you.

Klaus

If on Linux your best bet is probably something like:

val result = executeCommandLine("ls -l /path/to/file | wc -l", 5000)
if(result == "1") {
    // file exists
}
else {
    // file doesn't exist
}

I don’t know what the commands are for Windows.

1 Like

Here’s a portable solution…

import java.io.File

rule "example"
when
        <triggers...>
then
        var f = new File("filename")
        if (f.exists()) {
            // file exists
        }
        else {
            // file doesn't exist
        } 
end
3 Likes

Thank you very much

Mit freundlichen Grüßen

Klaus Rehbein
Zum Feldberg 23a
61389 Schmitten
klaus.rehbein@hotmail.demailto:klaus.rehbein@hotmail.de
0177 6175087