Sign in to follow this  
Followers 0
b8bboi

Monitoring A File For Access?

4 posts in this topic

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.

Share this post


Link to post
Share on other sites



per help

option [optional]Flag to indicate which timestamp

0 = Modified (default)

1 = Created

2 = Accessed

maybe try for the modified date???

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites

per help

maybe try for the modified date???

8)

Thanks but I don't need the modified date. I need to monitor the accessed date.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0