View difference between Paste ID: TZjiF4bb and MNsRmLsn
SHOW: | | - or go back to the newest paste.
1-
local file_path = "/path/to/your/file.txt" -- Replace this with your file's path
1+
local fileToMonitor = "yourfile.txt" -- Change this to your file name
2-
local interval = 5 -- Adjust the interval in seconds
2+
local interval = 5 -- Interval in seconds
3
4-
local function checkFile()
4+
local function monitorFile()
5-
    while true do
5+
  while true do
6-
        if not fs.exists(file_path) then
6+
    if fs.exists(fileToMonitor) then
7-
            print("File not found. Running code...")
7+
      -- Your code to send a message or perform actions when the file is found
8-
            -- Insert your code here to execute if the file is not found
8+
      -- For example: redstone.setOutput("back", true)
9-
            -- Example: shell.run("your_script")
9+
    else
10-
            -- Replace "your_script" with the script or command you want to execute
10+
      -- Your code to run when the file is not found
11-
            
11+
      -- For example: shell.run("program_to_execute")
12-
            return -- Exit the function after running the code
12+
13-
        end
13+
14-
        os.startTimer(interval) -- Set the timer to check again after the interval
14+
    os.startTimer(interval)
15-
        os.pullEvent("timer") -- Wait for the timer event
15+
    os.pullEvent("timer")
16
  end
17
end
18
19-
-- Start the background process
19+
local monitorThread = coroutine.create(monitorFile)
20-
parallel.waitForAny(checkFile, function() os.pullEvent("terminate") end)
20+
coroutine.resume(monitorThread)
21