--> Creating a Directory Along with Sub Directories Delphi | Delphi Tips Trick

For Newbie

Tuesday, 15 November 2011

Creating a Directory Along with Sub Directories Delphi

| Tuesday, 15 November 2011


Create a directory and its sub-directories with a single line of code.

Use the function: ForceDirectories (Dir: String): Boolean;
If the directory you want to create already exists, then the directory in question will automatically be replace.

Example usage (using SelectDirectory.):
procedure TForm1.Button1Click (Sender: TObject);
var
   s: String;
begin
   if SelectDirectory ('Select Dir','', s) then
     if not ForceDirectories (s + '\ dir1 \ dir2 \ dir3 \ dir4 \ dir5') then
       ShowMessage ('Failed');
end;

To be able to use the code as in the example, you should add the clause uses FileCtrl unit.

Related Posts

No comments: