Sign in to follow this  
Followers 0
leuce

How to detect change in file

6 posts in this topic

G'day everyone

Can you tell me what is the simplest way to detect if a file has been changed? I just need to detect when a file is changed, so that I can read its contents whenever it changes. It will be the same file all the time, with a known file name, and it's just the one file. The file size will usually be less than 10 kilobytes.

One way I can think of is to check the file's creation date ten times a second (and compare it with the previous check), but if you think this is a good method, can anyone tell me how to check a file's creation date? Another way may be to check the file's size -- not such an accurate method but it is likely that the file changes won't all be the same size. I guess I could even open, read and close the file ten times a second, and hope that the other program that writes to it won't clash with the script, but somehow I don't think that that would be the best way of doing it.

I look forward to your replies.

Samuel (leuce)

Share this post


Link to post
Share on other sites



well using FileGetTime, you can find the time that the file was last accessed (if the file is changed for sure after its accessed)

Share this post


Link to post
Share on other sites

you could read the files contents the first time, then see f its the same the second time, and if the file contents are not the same then take action


[center][/center][center]=][u][/u][/center][center][/center]

Share this post


Link to post
Share on other sites

you could read the files contents the first time, then see f its the same the second time, and if the file contents are not the same then take action

I think you misunderstood me. I don't need to determine whether the file's contents changes or not. It changes. It changes regularly. What I want the script to do is to detect *when* it changes so that action can be taken very shortly after it had changed. During the time that the script runs (a few hours, perhaps), the file will change several hundred times, and I would like to know about the change very, very shortly after it happens (within a 10th of a second, even).

Share this post


Link to post
Share on other sites

The usual way is to check the file's archive attribute. Turn it off at some point. Then if it's changed then the file has changed, assuming you don't need to gaurd against malicious programs. This is how many backup programs decide what has changed since the last backup.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

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