b8bboi Posted April 13, 2006 Share Posted April 13, 2006 Hi all, I need to write a script that sits in the background and monitors a file. Anytime that file is accessed, the script will do something. Here's my attempt. Should be simple enough. Opt("TrayAutoPause", 0) AutoItSetOption ( "TrayIconHide", 0 ) $FileToMonitor = "test.txt" $lastAccessTime = FileGetTime($FileToMonitor, 2, 1) While 1=1 $currentTime = FileGetTime($FileToMonitor, 2, 1) If $currentTime <> $lastAccessTime Then MsgBox(0, "", "File changed", 3) $currentTime = FileGetTime($FileToMonitor, 2, 1) $lastAccessTime = $currentTime EndIf Sleep(100) WEnd The problem is Windows caches files for accessing. If you keep opening a file multiple times, it'll be cached into RAM and the Access Time won't change. Is there any way to prevent this? Also, in C++, there's a function called FindFirstChangeNotification, which can give real-time info on a file, including access time. Is there an equivalence for AutoIt? If there's another way to do this, please tell me. Thanks. Link to comment Share on other sites More sharing options...
Valuater Posted April 13, 2006 Share Posted April 13, 2006 per help option [optional]Flag to indicate which timestamp 0 = Modified (default) 1 = Created 2 = Accessed maybe try for the modified date??? 8) Link to comment Share on other sites More sharing options...
JSThePatriot Posted April 13, 2006 Share Posted April 13, 2006 If you know much about C++ you could write a plug-in dll to use the function you mentioned to monitor the file in real time with AutoIt. I am sorry I dont have a more direct answer. JS AutoIt Links File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out. ComputerGetInfo UDF's Updated! 11-23-2006 External Links Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more) Link to comment Share on other sites More sharing options...
b8bboi Posted April 13, 2006 Author Share Posted April 13, 2006 per helpmaybe try for the modified date???8)Thanks but I don't need the modified date. I need to monitor the accessed date. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now