Solved

Detect a file change

Posted on 1997-09-05
7
752 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

932 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now