code:
/* File modification dates registry */
var FileModificationDates = [];
/**
* Listen for file modification
*
* @param string FilePath the file to observe
* @param function Callback function to call when the file is modified
* @return boolean
*
* @note : Callback function should take one argument which is the the path of the file
*/
function ListenForFileModification(FilePath, Callback) {
var DateLastModified = GetFileModificationDate(FilePath);
if (DateLastModified === false) return false;
Callback = Callback || function(FilePath) {};
FileModificationDates[FilePath] = {
file : FilePath,
date : DateLastModified,
callback : Callback
}
MsgPlus.AddTimer('LSTN_FileModification_' + FilePath, 100);
return true;
}
/**
* Get the file modification time
*
* @param string FilePath the file
* @return string
*
* @note : returns false if file does not exist
*/
function GetFileModificationDate(FilePath) {
var FileSystem = new ActiveXObject('Scripting.FileSystemObject');
if (!FileSystem.FileExists(FilePath)) return false;
var File = FileSystem.GetFile(FilePath);
return '' + File.DateLastModified + '';
}
/* common Timer event handler */
function OnEvent_Timer(TimerId) {
var TimerMatchLSTN = TimerId.match(/^LSTN_FileModification_(.+)$/);
if (TimerMatchLSTN.length && FileModificationDates[TimerMatchLSTN[1]]) {
var FilePath = TimerMatchLSTN[1];
var DateLastModified = GetFileModificationDate(FilePath);
if (DateLastModified === false) return false;
if (DateLastModified != FileModificationDates[FilePath].date) {
FileModificationDates[FilePath].callback(FilePath);
FileModificationDates[FilePath] = undefined;
return true;
}
MsgPlus.AddTimer('LSTN_FileModification_' + FilePath, 100);
return true;
}
}
// usage example :
ListenForFileModification(MsgPlus.ScriptFilesPath + '\\file.txt', function(FilePath){Debug.Trace('File modified : ' + FilePath)});
There's the code from MPScripts.net