leuce Posted December 10, 2009 Share Posted December 10, 2009 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) Link to comment Share on other sites More sharing options...
d0n Posted December 10, 2009 Share Posted December 10, 2009 well using FileGetTime, you can find the time that the file was last accessed (if the file is changed for sure after its accessed) Link to comment Share on other sites More sharing options...
IchBistTod Posted December 10, 2009 Share Posted December 10, 2009 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] Link to comment Share on other sites More sharing options...
leuce Posted December 10, 2009 Author Share Posted December 10, 2009 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 actionI 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). Link to comment Share on other sites More sharing options...
martin Posted December 10, 2009 Share Posted December 10, 2009 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. Link to comment Share on other sites More sharing options...
KaFu Posted December 10, 2009 Share Posted December 10, 2009 Take a look at the the MonitorFileActivity UDF / sample in my signature. OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) 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