Delphi Tips Trick

For Newbie

Iklan Responsive Atas

Responsive Ads Here

Tuesday, 15 November 2011

Creating a Directory Along with Sub Directories Delphi

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);
   s: String;
   if SelectDirectory ('Select Dir','', s) then
     if not ForceDirectories (s + '\ dir1 \ dir2 \ dir3 \ dir4 \ dir5') then
       ShowMessage ('Failed');

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

No comments: