Home  |  Delphi .net Home  |  System.IO.FileSystemWatcher  |  OnRenamed Method
  
OnRenamed  
Method  
A method that is called when a file is renamed
FileSystemWatcher Class
System.IO NameSpace
NotCF1.  Procedure OnRenamed ( Event : FileSystemEventArgs ) ;
CF : Methods with this mark are Compact Framework Compatible
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
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 
 
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.
   It was expected that when renaming a file in the C:\ folder would have triggered the OnRenamed method, but this was not the case.
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author