procedure ZsDelPath(mDirName: string); { 删除指定路径 }
var
  Sr: TSearchRec;
  PathName: string;
  K: Integer;
begin
  PathName := mDirName + '\*.*';
  K := FindFirst(PathName, faAnyFile, Sr);
  while K = 0 do begin
    if (Sr.Attr and faDirectory > 0) and (Pos(Sr.Name, '..') = 0) then begin
      Sr.Attr := 16;
      ZsDelPath(mDirName + '\' + Sr.Name);
    end else if Pos(Sr.Name, '..') = 0 then begin
      Sr.Attr := 0;
      DeleteFile(PChar(mDirName + '\' + Sr.Name));
    end;
    K := FindNext(Sr);
  end;
  RmDir(mDirName);
end; { ZsDelPath }procedure TForm1.Button1Click(Sender: TObject);
begin
  ZsDelPath('C:\Temp')
end;

解决方案 »

  1.   

    procedure ZsDelPath(mDirName: string); { 删除指定路径 }
    var
      Sr: TSearchRec;
      PathName: string;
      K: Integer;
    begin
      PathName := mDirName + '\*.*';
      K := FindFirst(PathName, faAnyFile, Sr);
      while K = 0 do begin
        if (Sr.Attr and faDirectory > 0) and (Pos(Sr.Name, '..') = 0) then begin
          FileSetAttr(Sr.Name, faDirectory);
    //    ~~~~~~~~~~加强删除只读、隐藏目录
          ZsDelPath(mDirName + '\' + Sr.Name);
        end else if Pos(Sr.Name, '..') = 0 then begin
          FileSetAttr(Sr.Name, 0);
          DeleteFile(PChar(mDirName + '\' + Sr.Name));
        end;
        K := FindNext(Sr);
      end;
      RmDir(mDirName);
    end; { ZsDelPath }procedure TForm1.Button1Click(Sender: TObject);
    begin
      ZsDelPath('C:\Temp')
    end;
      

  2.   

    你可以这样做,先在 uses里面加入 ShellApi,
    procedure copyfile(Ahandle: THandle; FileName: String);
    var
      SHFileOpStruct: TSHFileOpStruct;
    begin
      with SHFileOpStruct do
      begin
        Wnd := AHandle;
        wFunc:= FO_DELETE;
        pFROM:= Pchar(FileName);
        fFlags:= FOF_ALLOWUNDO;
      end;
      ShFileOperation(SHFileOpStruct);
    end;上面主要是用到了ShFileOperation这个API函数,具体应该看的懂了把?呵呵 
      

  3.   

    上面的filename参数也可变成DirName(目录或者是文件夹名称)