首页 > Windows开发 > 详细

转:delphi 删除指定文件夹下所有文件

时间:2015-04-03 12:54:37      阅读:180      评论:0      收藏:0      [点我收藏+]
function TFtpContentThd.DeleteDirectory(NowPath: string): Boolean;
var
  search: TSearchRec;
  ret: integer;
  key: string;
begin
  if NowPath[Length(NowPath)] <> ‘\‘ then
    NowPath := NowPath + ‘\‘;
  key := NowPath + ‘*.*‘;
  ret := findFirst(key, faanyfile, search);
  while ret = 0 do
  begin
    if ((search.Attr and fadirectory) = fadirectory) then
    begin
      if (search.Name <> ‘.‘) and (search.name <> ‘..‘) then
      begin
        DeleteDirectory(NowPath + search.name);
        removedir(NowPath + search.name); //如果需要删除文件夹则添加
      end;
    end
    else
    begin
      if ((search.Attr and fadirectory) <> fadirectory) then
      begin
        deletefile(PAnsiChar(NowPath + search.name));

      end;
    end;
    ret := FindNext(search);
  end;
  FindClose(search.FindHandle);
  //FindClose(search); //发现在线程里面不能用这,只能用上面的句柄
  //removedir(NowPath); //如果需要删除最外层文件夹则添加
  result := True;
end;

  

转:delphi 删除指定文件夹下所有文件

原文:http://www.cnblogs.com/rogge7/p/4389494.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!