Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to detect that a file has been altered

Status
Not open for further replies.

wduty

Programmer
Jun 24, 2000
271
0
0
US
I often see in programs (such as visual studio) a prompt indicating that a file which you have open has been modified by another user and whether or not you want to reload it. How would you go about doing this?

I usually use CreateFile for windows programs to read/write files, but I usually close the handle immediately after either reading or writing. I'm guesssing that I might have to open the file with FILE_SHARE_READ and FILE_SHARE_WRITE and then hang on to the handle and somehow monitor it for changes(?). Or perhaps there one or more of the access flags has to be set? Maybe a thread to monitor the handle or file state?

Anyone ever done this?
--Will Duty
wduty@radicalfringe.com

 
You should implement some interfaces as IPersist*. When the function IPersist*.IsDirty() returns true, you should reaload it. There are also some interfaces what contains in the name *Sink*. This interface notify VisualStudio what something are changed. John Fill
1c.bmp


ivfmd@mail.md
 
Most independent method is to check keeping the file date/time stamp. Using something like the WM_ACTIVATE or other messages to tell it to check the file again, your desired processes acting from there.
 
wduty -

Take a look at the change notification API calls:

FindFirstChangeNotification
FindNextChangeNotification
FindCloseChangeNotification

Chip H.
 
Dim fs, f, f1, fc
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(folderspec)
Set fc = f.Files
For Each f1 in fc

'Create a tag here adding the path to the file as the browser sees it.
Response.Write &quot;<A href=&quot; & f1.name & &quot;....>&quot; & f1.name & &quot;</a>&quot;
Next

Play with it and write to the browser until you get it correctly. Also remember the file needs to be available to the browser (
 
Opps, the last post went to the wrong forum..sorry
 
whoa! Thanks for all the responses! I will look at the different approaches and see which best suits what I am doing.
--Will Duty
wduty@radicalfringe.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top