码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2015-04-03 12:54:48      阅读:713      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!