Jump to content

Recommended Posts

Posted

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.

Posted

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)

Posted

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.

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...