如果不存在此目录就创建它:
 if not DirectoryExists(path1) then
    if not CreateDir(path1) then
    raise Exception.Create('Cannot create '+path1);但不存在的时候报错,没有这个目录,看来是没有自动创建目录啊,why?

解决方案 »

  1.   

    我试了好用的procedure TForm1.Button1Click(Sender: TObject);
    begin
      if not DirectoryExists('d:\tmp') then
        if not CreateDir('d:\tmp') then
          raise Exception.Create('Cannot create '+'d:\tmp');end;
      

  2.   

    我就是用的你那个啊,不过用的是变量而已。gmSysPath是当前程序目录,daystr是当前日期的天数。我这是数据库每天备份的目录
     
    path1:=trim(gmSysPath+'\'+daystr);但当没有此目录时报错
      

  3.   


    procedure TForm1.Button5Click(Sender: TObject);
    var
      path1:string;
    begin
      path1:=trim(extractfilepath(application.ExeName)+'\'+'123');
      if not DirectoryExists(path1) then
        if not CreateDir(path1) then
        raise Exception.Create('Cannot create '+path1);
    end;
    这样也好用啊!
      

  4.   

    你用showmessage(path1);看看path1是什么内容