您的位置:首页 > 其它

删除文件夹以及文件夹下的所有文件

2007-09-18 12:39 316 查看
procedure TForm1.DeleteFolder(psDelPath: string);
var
  loSr: TSearchRec;
begin
  if FindFirst(psDelPath + '/*.*', faAnyFile, loSr) = 0 then
  begin
    if loSr.Attr <> faDirectory then
      DeleteFile(psDelPath + '/' + loSr.Name)
    else
    begin
      if (loSr.Name <> '.') and (loSr.Name <> '..') then
      begin
        DeleteFolder(psDelPath + '/' + loSr.Name);
      end;
    end;

    while FindNext(loSr) = 0 do
    begin
      if loSr.Attr <> faDirectory then
      begin
        DeleteFile(psDelPath + '/' + loSr.Name);
      end
      else if (loSr.Name <> '.') and (loSr.Name <> '..') then
      begin
        DeleteFolder(psDelPath + '/' + loSr.Name);
      end;
    end;

    FindClose(loSr);
  end;
  RemoveDirectory(PChar(psDelPath));
end; 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  string