Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Detecting OS file operations

21 views
Skip to first unread message

Harold Holmes

unread,
May 12, 1998, 3:00:00 AM5/12/98
to

Is there a way that you can detect if a file has been copied, moved or
deleted in Win95/NT using Delphi? I am guessing it would be in the Shell
objects but am not sure where to look.

--
Best regards,
Harold Holmes
Lincoln Beach Software
http://www.lincolnbeach.com = Download Butler + SiteTrak + FlexSite


Nick Hodges (TeamB)

unread,
May 13, 1998, 3:00:00 AM5/13/98
to

Harold,

Check out the FindFirstChangeNotification family of API calls.


Nick Hodges
TeamB

Nick Hodges (TeamB)

unread,
May 13, 1998, 3:00:00 AM5/13/98
to

Harold,

Even better, here's a old message from my colleague Steve Schafer --

-------------------------------------
On Thu, 03 Jul 1997 14:09:09 -0400, Colby Makowsky <co...@cyberhq.com>
wrote:
>I would like to have an event occur
when a specific directory or
>registry key is updated. Similar to
the explorer, which 'Refreshes' the
>listview when a file is changed, i
would like to be able to do a similar
>thing with my app. Thank you!
[reply to your email message]

Here's an example of a thread object
that waits for file and directory
changes and pops up a message box
when one occurs:

type
TChangeThread = class(TThread)
protected
ChangeHandle: THandle;
FPathToWatch: String;
procedure Execute; override;
procedure NotifyChange;
public
constructor Create(const
PathToWatch: String);
end;

constructor
TChangeThread.Create(const PathToWatch: String);
begin
inherited Create(True);
FPathToWatch := PathToWatch;
FreeOnTerminate := True;
ChangeHandle :=
FindFirstChangeNotification(PChar(FPathToWatch),
True, FILE_NOTIFY_CHANGE_FILE_NAME
or
FILE_NOTIFY_CHANGE_DIR_NAME);
Resume;
end;

procedure TChangeThread.Execute;
var
WaitResult: DWORD;
begin
repeat
WaitResult :=
WaitForSingleObject(ChangeHandle, 500);
if WaitResult = WAIT_OBJECT_0 then
begin
Synchronize(NotifyChange);

FindNextChangeNotification(ChangeHandle);
end;
until Terminated;

FindCloseChangeNotification(ChangeHandle);
CloseHandle(ChangeHandle);
end;

procedure
TChangeThread.NotifyChange;
begin
ShowMessage('Change occurred in ' +
FPathToWatch);
end;

To begin notifications:

MyChgThread :=
TChangeThread.Create('D:\Scratch');

To end them:

MyChgThread.Terminate;

-Steve
-------------------------------------------------------------
Nick Hodges
TeamB

Harold Holmes

unread,
May 14, 1998, 3:00:00 AM5/14/98
to

Nick Hodges (TeamB) wrote in message
<35590711....@forums.borland.com>...


>Harold,
>
>Even better, here's a old message from my colleague Steve Schafer --

Thanks Nick. Do you know if there is a API call to tell which particular
file was added/renamed/deleted?

0 new messages