求在DELPHI中删除非空文件夹的思路及源码?!我要在程序中删除某些文件夹。给个思路及源码!谢谢![email protected]

解决方案 »

  1.   

    你可以参考一下下面的代码,我没有测试过!
    //删除子目录及其下文件//This doesn't check for attributes being set, which might preclude deletion of a file. Put a {$I-} {$I+} pair around the functions that cause the problem.procedure removeTree (DirName: string);
    var
      FileSearch: tSearchRec;
    begin
      { first, go through and delete all the directories }
      chDir (DirName);
      FindFirst ('*.*', faDirectory, FileSearch);
      while (getlastError = 0) do
      begin
        if (FileSearch.name <> '.')
         AND (FileSearch.name <> '..')
         AND ((FileSearch.attr AND faDirectory) <> 0)
        then begin
          if DirName[length(DirName)] = '\' then
            removeTree (DirName+FileSearch.Name)
          else
            removeTree (DirName+'\'+FileSearch.Name);
          ChDir (DirName);
        end;
        FindNext (FileSearch)
      end;
      {then, go through and delete all the files }
      FindFirst ('*.*', faAnyFile, FileSearch);
      while (getlastError = 0) do
      begin
        if (FileSearch.name <> '.')
         AND (FileSearch.name <> '..') then
         deletefile(FileSearch.name);  //Remove和WorkDir是何意,删除文件?
        FindNext (FileSearch)
      end;
      rmDir (DirName)       //应进入上层目录
    end;
      

  2.   

    uses shellApi;
    ----------
    procedure TForm1.Button7Click(Sender: TObject);
    var
      sh:TSHFileOpStruct;
    begin
      sh.Wnd :=Handle;
      sh.pFrom:=PChar('D:\复件 TCWork');
      sh.wFunc:=FO_DELETE ;
      sh.fFlags:=FOF_SIMPLEPROGRESS ;
      sh.lpszProgressTitle:=Pchar('Delete File');
      SHFileOperation(sh);
    end;
      

  3.   

    就用SHFileOperation吧,,
    快捷、方便
      

  4.   

    cll007(gazo)说得对用SHFileOperation
      

  5.   

    我在XP下做了!
    我的磁盘格式是NTFS。我用的DELPHI 是7!
      

  6.   

    给大家推荐个好网站
    http://www.djtz.net/get.asp?get=9662