Solved

Detect a file change

Posted on 1997-09-05
7
758 Views
Last Modified: 2012-08-13
How to detect a file has been changed using something like a shell extension or a hook...

(I don't want a TTimer with constantly checking if a file's date is any different)
0
Comment
Question by:kolarb
7 Comments
 
LVL 8

Expert Comment

by:ZifNab
ID: 1343963
For what do you want to know the change of the file?
 Progressbar for copy of file?

Why has it be checked the whole time?
0
 
LVL 3

Expert Comment

by:mirek071497
ID: 1343964
You can do  this with setting Notification but only in WindowsNT. In WIndows95 this is impossible and you must use timer.

For WinNT i can write simple code.
0
 
LVL 2

Author Comment

by:kolarb
ID: 1343965
ZifNab: When a user changes a file a program should be run. It is known which files should be looked at.

mirek: ?? check examples/demos/shellext examples in Delphi3. I thought something like that should be possible. Anyway show me your NT code and I'll reconsider your answer.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:arh
ID: 1343966
As far as i know, there is no shell extension of this kind. But there is a pair of API functions - FindFirstChangeNotificaion/FindNextChangeNotification, available in both win95 and NT, which will notify you when any file in a particular directory has been changed. You should determine which particular file in that directory was changed by examining its date/time or something like that.
And to receive such notification your program should be running
constantly in background.
Sorry, i can't give you an example now.
0
 
LVL 3

Accepted Solution

by:
mirek071497 earned 100 total points
ID: 1343967
Thanx to arh !!!!

As "arh" write i try test if notification works on Win95.
I found so yes but with some limitations. I don't have enought time to test what working and what not working but this example working.

var stop : boolean;

procedure TForm1.Button1Click(Sender: TObject);
var
  dwWaitStatus   : DWORD;
  dwChangeHandle : THandle;
begin
  Stop := False;
  dwChangeHandle := FindFirstChangeNotification(
    'C:\',                        //  directory to watch
    FALSE,                        // do not watch the subtree
                                  // in Win95 You can't set this to true !!!!
    FILE_NOTIFY_CHANGE_DIR_NAME); // watch filename changes

  if dwChangeHandle=INVALID_HANDLE_VALUE then
    begin
      ShowMessage('I can''t set notification' );
      ExitProcess(GetLastError)
    end;
  while (stop=false) do
  begin
    dwWaitStatus := WaitForSingleObject(dwChangeHandle, 100);
    if dwWaitStatus=WAIT_OBJECT_0 then
      begin
        Memo1.Lines.Add( 'File Created, Renamed or Deleted in C:\' );
      //here you can compare previous list of files with current list of files
      //and find what was changed
        if FindNextChangeNotification(dwChangeHandle)=FALSE then
        begin
          ShowMessage('I can''t restart notification' );
          ExitProcess(GetLastError);
        end;
      end;
    Application.ProcessMessages;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Stop := True;
end;



0
 
LVL 2

Author Comment

by:kolarb
ID: 1343968
Excellent!
Will try it now and grade the answer.
0
 
LVL 2

Author Comment

by:kolarb
ID: 1343969
Thank you guys&gals.
Searched the MSDN and found this example with other settings.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question