linux社区爱心援助Linux认证系列教程业界动态站务新闻公司招聘网络学院网址大全LPI专题CISCO专题
设为首页
加入收藏
管理团队
JSP  
JAVA  
PERL  
 您的位置:首页 > 开发语言 > Delphi >
栏目导栏
  php
  JSP
  ASP
  asp.net
  JAVA
  c/c++/c#
  perl
  JavaScript
  Basic
  Delphi
资料搜索
热门文章
·HexToStr函数和StrToHex函数
·Delphi中的进制转换
·delphi轻松设置无边框透明窗体
·delphi第三方控件安装(Ehlib)
·DELPHI组件安装全攻略
·delphi动态创建控件
·开发工具比较Visual C++ VS De
·delphi完整身份证效验程序实例
·delphi中的Format函数详解
·delphi编程获取打印机的打印任
·如何判断文本文件的编码格式
·深入研究Variant数组
·用delphi编写网络游戏的外挂
·Delphi技巧-用户自定义数据类型
·delphi设置控件透明
最新文章
·在应用程序中跟踪MOUSE的坐标
·压缩和修复MS Access 2000文件
·DELPHI 6.0 动画制做
·怎样在Delphi中调用LastError信
·怎样得到主域服务器名称
·怎样利用递归实现删除某一目录
·读出主键下所有项
·如何制作照片底片效果的图像(
·获得Modem的状态
·WebBrowser屏幕滚动的实现,设
·有关字符串处理的小技巧
·Delphi建立键盘鼠标动作纪录与
·Delphi中布尔类型辨析
·DELPHI程序注册码设计
·图形的不规则的Copy
Google
 
怎样利用递归实现删除某一目录下所有文件
[ 作者:  加入时间:2007-12-13 12:58:01  来自:Linux联盟收集整理 ]
var Form1: TForm1;2qxLinux联盟
rec_stack:array [1..30] of TSearchRec;2qxLinux联盟
rec_pointer:integer;2qxLinux联盟
Del_Flag:Boolean;2qxLinux联盟
2qxLinux联盟
2qxLinux联盟
------------------------------------------------------------------ ------2qxLinux联盟
2qxLinux联盟
procedure TForm1.DeleteTree(s:string);2qxLinux联盟
VAR searchRec:TSearchRec;2qxLinux联盟
begin2qxLinux联盟
  if FindFirst(s+'\*.*', faAnyFile, SearchRec)=0 then2qxLinux联盟
  repeat2qxLinux联盟
  if (SearchRec.Name<>'.') and (SearchRec.Name<>'..') then2qxLinux联盟
  begin2qxLinux联盟
    if (SearchRec.Attr and faDirectory>0) then2qxLinux联盟
    begin2qxLinux联盟
      rec_stack[rec_pointer]:=SearchRec;2qxLinux联盟
      rec_pointer:=rec_pointer-1;2qxLinux联盟
      DeleteTree(s+'\'+SearchRec.Name);2qxLinux联盟
      rec_pointer:=rec_pointer+1;2qxLinux联盟
      SearchRec:=rec_stack[rec_pointer];2qxLinux联盟
    end2qxLinux联盟
    else2qxLinux联盟
    begin2qxLinux联盟
      try2qxLinux联盟
        FileSetAttr(s+'\'+SearchRec.Name,faArchive);2qxLinux联盟
        DeleteFile(s+'\'+SearchRec.Name);2qxLinux联盟
        except2qxLinux联盟
          Application.MessageBox(PChar('Delete File:'+s+'\'+SearchRec.Name+' Error!'),'Info',MB_OK);2qxLinux联盟
          Del_Flag:=False;2qxLinux联盟
        end;2qxLinux联盟
      end;2qxLinux联盟
    end;2qxLinux联盟
    until (FindNext(SearchRec)<>0);2qxLinux联盟
    FindClose(SearchRec);2qxLinux联盟
    if rec_pointer<30 then2qxLinux联盟
    begin2qxLinux联盟
      try2qxLinux联盟
        FileSetAttr(s,faArchive);2qxLinux联盟
        RemoveDir(s);2qxLinux联盟
        except2qxLinux联盟
          Application.MessageBox(PChar('Delete Directory:'+s+' Error!'),'Info',MB_OK);2qxLinux联盟
          Del_Flag:=False;2qxLinux联盟
        end;2qxLinux联盟
      end;2qxLinux联盟
    end;2qxLinux联盟
    2qxLinux联盟
    2qxLinux联盟
    ---------------------------------------------------------2qxLinux联盟
    2qxLinux联盟
    Del_Flag:=True;2qxLinux联盟
    rec_pointer:=30;2qxLinux联盟
    DeleteTree('c:\temp');2qxLinux联盟
    if Del_Flag then Application.MessageBox(PChar('目录c:\temp的内容已成功清除!'),'信息',MB_OK);2qxLinux联盟
2qxLinux联盟
堆栈调用作得很丑,还有无更好的方法,请跟我联系。2qxLinux联盟
Linux联盟收集整理 ,转贴请标明原始链接,如有任何疑问欢迎来本站Linux论坛讨论
评论】【加入收藏夹】【 】【打印】【关闭
※ 相关链接
 ·使用Javascript创建XML文件  (2007-12-12 16:44:30)
 ·Linux操作系统下ISO镜像文件的制作与刻录  (2007-12-12 11:56:07)
 ·Ubuntu下VirtualBox 1.4.0设置文件共享  (2007-12-11 11:59:32)
 ·Windows与Linux系统共享StarDict字典文件  (2007-12-11 11:53:47)
 ·Linux操作系统如何显示中文目录和文件名  (2007-12-07 13:50:51)
 ·如何恢复调用Firefox浏览器中的缓存文件  (2007-12-07 13:50:08)
 ·Linux下使用SSH客户端及其Sftp文件传送  (2007-12-07 13:49:27)
 ·Linux内核isdn_net.c文件 本地溢出漏洞  (2007-12-07 13:48:23)
 ·为Linux操作系统下的文件 分配多个权限  (2007-12-06 17:56:38)
 ·Linux操作系统的可执行文件格式详细解析  (2007-12-05 17:26:34)