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+ has 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 Files\\My Game\\Audio\\Speech');
Tags: borland, code, create, Delphi, directories, folders, freeware, inside, multiple, object pascal, open source, source code, sources, tip, trick
Merlin’s Delphi Forge
Leave a comment