这是Delphi的例子,相信你也能用procedure ForceDirectories(Dir: string); begin if Length(Dir) = 0 then raise Exception.Create(SCannotCreateDir); if (AnsiLastChar(Dir) <> nil) and (AnsiLastChar(Dir)^ = '\') then Delete(Dir, Length(Dir), 1); if (Length(Dir) < 3) or DirectoryExists(Dir) or (ExtractFilePath(Dir) = Dir) then Exit; // avoid 'xyz:\' problem. ForceDirectories(ExtractFilePath(Dir)); CreateDir(Dir); end;
begin
if Length(Dir) = 0 then
raise Exception.Create(SCannotCreateDir);
if (AnsiLastChar(Dir) <> nil) and (AnsiLastChar(Dir)^ = '\') then
Delete(Dir, Length(Dir), 1);
if (Length(Dir) < 3) or DirectoryExists(Dir)
or (ExtractFilePath(Dir) = Dir) then Exit; // avoid 'xyz:\' problem.
ForceDirectories(ExtractFilePath(Dir));
CreateDir(Dir);
end;
麻烦将程序用C++改写一下,谢谢。