Back


Lennie's Weekly Tip: Creating & Removing a Directory

28 June 2000 Ref. 27

To create a new directory (folder) from your application(s), you can use the CreateDir function.
To remove an existing directory you can use the RemoveDir function.
 

CREATEDIR
=========

Declaration
-----------

function CreateDir(const Dir: string): Boolean;

Description
-----------

The CreateDir function creates a new directory.
The return value is TRUE if a new directory was successfully created, or FALSE if an error occurred.

Example
-------

if (not CreateDir('C:\OBOY')) then
  Messagedlg('Error: Can''t create a new directory', mterror, [mbok], 0);

In this example the CreateDir function will create a new directory (C:\OBOY) and will display a error message if unsuccessful.
 

REMOVEDIR
---------

Declaration
-----------

function RemoveDir(const Dir: string): Boolean;

Description
-----------

Call RemoveDir to remove the directory specified by the Dir parameter.
The return value is TRUE if a new directory was successfully deleted, FALSE if an error occurred.
The directory must be empty before it can be successfully deleted.

Example
-------

if (not RemoveDir('C:\OBOY')) then
  Messagedlg('Error: Unable to remove directory', mterror, [mbok], 0);

In this example the RemoveDir function will remove an existing directory (C:\OBOY) and will display a error message if unsuccessful.
 

NOTE: Remember to add the SysUtils unit to your application's uses-clause.
 

For more information read Delphi's on-line help.


Back