Sample scripts are provided as-is with no warranty of fitness for a particular purpose. These scripts are solely intended to demonstrate techniques for accomplishing common tasks. Additional script logic and error-handling may need to be added to achieve the desired results in your specific environment.
Lockfiles provide a simple way to limit access to a file, script, or process.
Consider the example where you have scheduled a script to run once every minute, but you are concerned about what happens if the script takes longer than a minute to run -- you don't want two copies of the script running at the same time. In that case, you might want Robo-FTP to silently exit and wait for the next minute to run again.
This sample script performs an atomic rename of a preexisting lockfile "unlocked.txt" to "locked.txt" before it begins processing. It renames it back when it is done. If the rename fails it means the file is already named "locked.txt" so the script simply exits.
1 RENAME "unlocked.txt" "locked.txt" 2 IFERROR RETURN $ERROR_SUCCESS 3 ; locked.txt acquired. 4 5 ; do work, when done whether in error or not 6 GOTO unlock 7 8 :unlock 9 ; Processing is done, so rename to unlocked.txt 10 RENAME "locked.txt" "unlocked.txt"