Home  |  Delphi .net Home  |  System.IO.FileSystemWatcher  |  OnDeleted Method
  
OnDeleted  
Method  
A method that is called when a file is deleted
FileSystemWatcher Class
System.IO NameSpace
NotCF1.  Procedure OnDeleted ( Event : FileSystemEventArgs ) ;
CF : Methods with this mark are Compact Framework Compatible
Description
The OnDeleted method is called when the Deleted event is triggered.
Notes
The author was unable to get the OnDeletedmethod 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 OnDeleted (Events : FileSystemEventArgs);
  end;

var
  MyWatcher : MyWatcherClass;

procedure MyWatcherClass.OnDeleted(Events: FileSystemEventArgs);
begin
  // It is crucial that the inherited OnDeleted method is called
  inherited OnDeleted(Events);

  // Indicate that we have detected a file or folder deletion
  Console.WriteLine(Events.FullPath + ' has been deleted');
end;

// Main code
begin
  // Create an object inherited from the FileSystemWatcher class
  MyWatcher := MyWatcherClass.Create('C:\');

  // Watch for any file access
  MyWatcher.NotifyFilter := NotifyFilters.LastAccess;

  // Now we wait until an event occurs -
  // MyWatcher will notify us of changes
  MyWatcher.WaitForChanged(WatcherChangeTypes.Deleted);

  Console.Readline;
end.
   It was expected that when deleting a file in the C:\ folder would have triggered the OnDeleted method, but this was not the case.
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author