您现在的位置:首页 >> 基础算法 >> window基础 >> 内容

Delphi中递归删除根目录中的空目录

时间:2011/9/3 15:30:47 点击:

  核心提示:procedure RemoveEmptyFolders(const rootFolder : string) ;var fd: TWin32FindData; h: THandle; rf: str...
procedure RemoveEmptyFolders(const rootFolder : string) ;
var
  fd: TWin32FindData;
  h: THandle;
  rf: string;
begin
  rf := IncludeTrailingBackslash(rootFolder) ;
  h := FindFirstFile(PChar(rf + '*.*'), fd) ;
  if h <> INVALID_HANDLE_VALUE then
  try
    with fd do
    repeat
      if (dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY > 0) and (Pos(cFileName,'.;..') = 0) then
      begin
        if not RemoveDir(rf + cFilename) then RemoveEmptyFolders(rf + cFileName) ;
      end;
    until not FindNextFile(h,fd) ;
  finally
    Windows.FindClose(h) ;
  end;
end;

作者:网络 来源:转载
共有评论 0相关评论
发表我的评论
  • 大名:
  • 内容:
  • 盒子文章(www.2ccc.com) © 2024 版权所有 All Rights Reserved.
  • 沪ICP备05001939号