Description |
The OnRenamed method is called when the Renamed event is triggered.
|
| Notes | The author was unable to get the OnRenamed method invoked in the sample code. Am awaiting a response from Borland to help on this matter.
|
|
Microsoft MSDN Links |
System.IO
System.IO.FileSystemWatcher
|
|
|
A simple example |
program Project1;
{$APPTYPE CONSOLE}
uses
System.IO;
// Class definition code
type
MyWatcherClass = Class(System.IO.FileSystemWatcher)
published
procedure OnRenamed (Events : RenamedEventArgs);
end;
var
MyWatcher : MyWatcherClass;
procedure MyWatcherClass.OnRenamed(Events: RenamedEventArgs);
begin
// It is crucial that the inherited OnRenamed method is called
inherited OnRenamed(Events);
// Indicate that we have detected a file or folder renaming
Console.WriteLine(Events.FullPath + ' was renamed');
end;
// Main code
begin
// Create an object inherited from the FileSystemWatcher class
MyWatcher := MyWatcherClass.Create('C:\');
// Watch for any file error
MyWatcher.NotifyFilter := NotifyFilters.LastAccess;
// Now we wait until an event occurs -
// MyWatcher will notify us of changes
MyWatcher.WaitForChanged(WatcherChangeTypes.Renamed);
Console.Readline;
end.
| Show full unit code | It was expected that when renaming a file in the C:\ folder would have triggered the OnRenamed method, but this was not the case.
|
|
|
|