- Code: Select all
use strict semicolons;
use strict variables;
// file to check
var file_name = "c:\\sample.txt";
// initialize the file info
var file = new FileInfo(file_name);
var file_modified = file.getLastWriteTime();
var file_size = file.getLength();
var file_modified_last = file_modified;
var file_size_last = file_size;
Console.writeLine("Starting...");
// check the file
var count = 0;
while (1)
{
// wait 1/2 second between checks
System.sleep(500);
count++;
// get the current modified time and file size
file_modified = file.getLastWriteTime();
file_size = file.getLength();
// limit the number of checks
if (count > 120)
break;
// if the file hasn't changed, do nothing
if (file_modified_last == file_modified ||
file_size_last == file_size)
{
continue;
}
// the file has changed
Console.writeLine(file_name + " changed.");
// reset modified time and file size to last values
file_modified_last = file_modified;
file_size_last = file_size;
}
Console.writeLine("Finished.");
Kirix Support Forums
Script to check if a file changes
1 post
• Page 1 of 1
Script to check if a file changes
Recently, we had a question about how to monitor a file to see if it changes. Here's a small script that shows how to do this:
Aaron Williams
Kirix Support Team
Kirix Support Team
-
Aaron - Kirix Support Team
- Posts: 120
- Joined: Fri Dec 16, 2005 3:01 pm
1 post
· Page 1 of 1
Return to Strata Help & Feedback