各位大虾好!!!小弟想实现如何删除当前路径下不为空的目录,据小弟所知的只有能删除空目录的方法,不知道Delphi有没有提供删除非空目录的方法啊,请各位大虾指教一下,谢谢!!!

解决方案 »

  1.   

    这得自己写个函数才行的procedure DelDir(SourcePath: String);
    var
      sr: TSearchRec;
    begin
      SourcePath:=IncludeTrailingPathDelimiter(SourcePath);
      if FindFirst(SourcePath + '*.*', faAnyFile, sr) = 0 then
      begin
        repeat
          DeleteFile(SourcePath + sr.Name);
        until FindNext(sr) <> 0;
        FindClose(sr);
        RemoveDir(SourcePath);
      end;
    end;
      

  2.   

    uses ShellAPI; //use SHFileOperation()、TSHFileOpStructfunction DeleteDirectory(mSource: string): Boolean;
    var
      vSHFileOpStruct: TSHFileOpStruct;
    begin
      FillChar(vSHFileOpStruct, SizeOf(vSHFileOpStruct), 0);
      with vSHFileOpStruct do
      begin
        Wnd := Application.Handle;
        wFunc := FO_DELETE;
        pFrom := PChar(mSource + #0);
        pTo := #0#0;
        fFlags := FOF_NOCONFIRMATION+FOF_SILENT;
      end;
      Result := SHFileOperation(vSHFileOpStruct) = 0;
    end; { DeleteDirectory }procedure TForm1.Button1Click(Sender: TObject);
    begin
      DeleteDirectory('C:\temp');
    end;