如何在Delphi里删除文件夹?,文件夹中所有文件一起删除.
有通用涵数最好,
或给代码列子.

解决方案 »

  1.   

    ShellAPI:
    SHFileOperation这类问题N次啦http://lysoft.7u7.net
      

  2.   

    procedure DeleteDir(sDirectory: String);
    //删除目录和目录下得所有文件和文件夹
    var
      sr: TSearchRec;
      sPath,sFile: String;
    begin
      //检查目录名后面是否有 '\'
      if Copy(sDirectory,Length(sDirectory),1) <> '\' then
        sPath := sDirectory + '\'
      else
        sPath := sDirectory;  //------------------------------------------------------------------
      if FindFirst(sPath+'*.*',faAnyFile, sr) = 0 then
      begin
        repeat
          sFile:=Trim(sr.Name);
          if sFile='.' then Continue;
          if sFile='..' then Continue;      sFile:=sPath+sr.Name;
          if (sr.Attr and faDirectory)<>0 then
            DeleteDir(sFile)
          else if (sr.Attr and faAnyFile) = sr.Attr then
            DeleteFile(sFile);                        //删除文件
        until FindNext(sr) <> 0;
        FindClose(sr);
      end;
      RemoveDir(sPath);
      //------------------------------------------------------------------
    end;
      

  3.   

    但只能对空文件夹管用
    要先用DeleteFile()删除里面的文件
      

  4.   

    谢谢大家了.
    solokey(永远的菜鸟-努力的学习ing-数据库太弱,被鄙视) () 
    ly_liuyang(Liu Yang) ()
    firstshine(黑里透红) () 
    他们的方法估计都可以,先顶两天再结,让更多的象我一样的新手看看.