文件磁盘相关函数[7]-建立文件夹 CreateDir; CreateDirectory; ForceDirectories

代码如下:

procedure TForm1.N12Click(Sender: TObject);
//建立文件夹 CreateDir; CreateDirectory; ForceDirectories
var
  dir: string;
  Bool: Boolean;
begin
  dir := 'f:\test';
  if not DirectoryExists(dir) then //先判断文件夹在不在,不在再创建
    Bool:=CreateDir(dir);  //返回 Boolean
    if Bool then
    ShowMessage('建立文件夹成功')
    else
    ShowMessage('建立文件夹失败');

  //也可以直接用API:
  //CreateDirectory(PChar(dir),nil);  //返回 Boolean

  //如果缺少上层目录将自动补齐:
  //dir := 'f:\test\CodeGear\Delphi\巅枫';
  //ForceDirectories(dir);  //返回 Boolean
end;

 

下面进行函数分析:

function CreateDir(const Dir: string //文件夹路径的字符串,如'f:\test',不含'\'
                  ): Boolean;   //返回布尔值,成功则true,否则false

相关文章:

  • 2022-02-16
  • 2022-01-02
  • 2022-12-23
  • 2021-07-08
  • 2022-12-23
  • 2022-12-23
  • 2021-12-21
  • 2021-07-30
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案