Home  |  Delphi .net Home  |  System.IO.File  |  Exists Method
Exists  
Method  
Returns true if the specified file exists
File Class
System.IO NameSpace
CF1.  Function Exists ( PathString : String; ) : Boolean; Static;
CF : Methods with this mark are Compact Framework Compatible
Description
Returns true if the file specified in PathString exists, otherwise false.
Microsoft MSDN Links
System.IO
System.IO.File
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

uses
  System.IO;

var
  Path   : String;
  Writer : StreamWriter;

begin
  // Create a text file
  Path := 'C:\DelphiBasics.txt';
  Writer := System.IO.File.CreateText(Path);

  // Close the file
  Writer.Close;

  if System.IO.File.Exists(Path)
  then Console.WriteLine('File exists')
  else Console.WriteLine('File does not exist');

  // Now delete this file
  Console.WriteLine;
  Console.WriteLine('Deleting the file :');
  Console.WriteLine;
  System.IO.File.Delete(Path);

  if System.IO.File.Exists(Path)
  then Console.WriteLine('File exists')
  else Console.WriteLine('File does not exist');

  Console.Readline;
end.
Show full unit code
  File exists
  
  Deleting the file :
  
  File does not exist
 
 
Delphi Programming © Neil Moffatt All rights reserved.  |  Contact the author