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

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

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

uses
  System.IO;

var
  FileInfo : System.IO.FileInfo;
  Files    : Array of String;
  Stream   : FileStream;
  i        : Integer;

begin
  // Create a FileInfo object for a text file
  FileInfo := System.IO.FileInfo.Create('DelphiBasics.txt');

  // Create the DelphiBasics.txt file
  Stream := FileInfo.&Create;

  // 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;

  FileInfo.Delete;

  // 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 new file
  System.IO.File.Delete('RenamedDelphiBasics.txt');

  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