?
Solved

Detect a file change

Posted on 1997-09-05
7
Medium Priority
?
768 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: 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 200 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

777 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