Home  |  Delphi .net Home  |  System.IO.File  |  Delete Method
  
Delete  
Method  
Deletes the specified file
File Class
System.IO NameSpace
CF1.  Procedure Delete ( PathString : String ) ; Static;
CF : Methods with this mark are Compact Framework Compatible
Description
The specified file is deleted.
Microsoft MSDN Links
System.IO
System.IO.File
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

uses
  System.IO;

var
  Path   : String;
  Files  : Array of String;
  Stream : FileStream;
  i      : Integer;

begin
  // Create the DelphiBasics.txt file
  Path := 'DelphiBasics.txt';
  Stream := System.IO.File.&Create(Path);

  // Close the file
  Stream.Close;

  // List files in the current folder
  Files := System.IO.Directory.GetFiles(Directory.GetCurrentDirectory);

  for i := 0 to Length(Files)-1 do
    Console.WriteLine(System.IO.Path.GetFileName(Files[i]));

  // Delete the file
  Console.WriteLine;
  Console.WriteLine('Deleting DelphiBasics.txt :');
  Console.WriteLine;

  System.IO.File.Delete(Path);

  // List files in the current folder
  Files := System.IO.Directory.GetFiles(Directory.GetCurrentDirectory);

  for i := 0 to Length(Files)-1 do
    Console.WriteLine(System.IO.Path.GetFileName(Files[i]));

  // Clean up - delete the file
  System.IO.File.Delete(Path);

  Console.Readline;
end.
   DelphiBasics.txt
   Project1.exe
   Project1.pdb
   Project1.rsp
  
   Deleting DelphiBasics.txt :
  
   Project1.exe
   Project1.pdb
   Project1.rsp
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author