How to Create Multiple Directories

The standard MkDir() function can create only one directory, it can not create subdirectories at one time. This function allows you to create multiple directories (directories inside directories). Delphi 4+ have the ForceDirectories() routine which does the same thing. It is declared in the FileCtrl unit.

uses
  SysUtils, FileCtrl;
...
procedure MkDirMulti(sPath: string);
begin
  if sPath[Length(sPath)] = '' then
    sPath := Copy(sPath, 1, Length(sPath - 1));

  if (Length(sPath) < 3) or DirectoryExists(sPath) then
    Exit;

  MkDirMulti(SysUtils.ExtractFilePath(sPath));
  try
    MkDir(sPath);
  except
    { Handle errors }
  end;
end;

Example: MkDirMulti(’C:Program FilesMy GameAudioSpeech’);

Tags: , , , , , , , , , , , , , , , , ,

No Comments Yet

You can be the first to comment!

Leave a comment

OpenID Login

Standard Login