Description |
The DirectoryExists function returns True if the given DirectoryName file exists.
The directory is searched for in the current directory.
False may be returned if the user is not authorised to see the file.
|
|
|
Example code : Check for a directory before and after deleting it |
// Full Unit code. // ----------------------------------------------------------- // You must store this code in a unit called Unit1 with a form // called Form1 that has an OnCreate event called FormCreate. unit Unit1; interface uses SysUtils, // Unit containing the DirectoryExists command Forms, Dialogs; type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} // Include form definitions procedure TForm1.FormCreate(Sender: TObject); var
dirName : String;
begin // Create a new directory
dirName := 'Test Folder';
CreateDir(dirName);
// Now see if the directory exists
if DirectoryExists(dirName)
then ShowMessage(dirName+' exists OK')
else ShowMessage(dirName+' does not exist');
// Delete the directory and look again
RemoveDir(dirName);
if DirectoryExists(dirName)
then ShowMessage(dirName+' still exists!')
else ShowMessage(dirName+' no longer exists');
end; end.
|
Hide full unit code |
Test Folder exists OK
Test Folder no longer exists
|
|