批量删除目录和目录下得所有文件和文件夹

该日志由 samool 发表于 2007-10-09 12:08 PM

delphi代码
  1. procedure   DeleteDir(sDirectory:   String);      
  2.   //删除目录和目录下得所有文件和文件夹      
  3.   var      
  4.       sr:   TSearchRec;      
  5.       sPath,sFile:   String;      
  6.   begin      
  7.       //检查目录名后面是否有   '\'      
  8.       if   Copy(sDirectory,Length(sDirectory),1)   <>   '\'   then     
  9.           sPath   :=   sDirectory   +   '\'     
  10.       else     
  11.           sPath   :=   sDirectory;     
  12.       
  13.       //------------------------------------------------------------------     
  14.       if   FindFirst(sPath+'*.*',faAnyFile,   sr)   =   0   then     
  15.       begin     
  16.           repeat     
  17.               sFile:=Trim(sr.Name);     
  18.               if   sFile='.'   then   Continue;     
  19.               if   sFile='..'   then   Continue;      
  20.        
  21.               sFile:=sPath+sr.Name;      
  22.               if   (sr.Attr   and   faDirectory)<>0   then      
  23.                   DeleteDir(sFile)      
  24.               else   if   (sr.Attr   and   faAnyFile)   =   sr.Attr   then      
  25.                   DeleteFile(sFile);                                                 //删除文件      
  26.           until   FindNext(sr)   <>   0;      
  27.           FindClose(sr);      
  28.       end;      
  29.       RemoveDir(sPath);      
  30.       //------------------------------------------------------------------      
  31.   end;   

 傻猫网络日志标签:    delphi, 批量删除, 文件, 文件夹
网摘: Yahoo Baidu Google Bolaa 365Key Yesky Wozhai POCO ViVi YouNote Hexun Del.icio.us Yeeyoo igooi I2Key Cn3 Bytemen Furl Blinklist Blogmarks Technorati 分享到饭否
相关文章: (最多只显示8条记)
如何判断按下的是回车键? (浏览:744, 评论:0)
Borland把Delphi卖掉了 (浏览:571, 评论:0)
Delphi如何开发游戏外挂 (浏览:1178, 评论:0)
Delphi大富翁论坛离线数据大全 (浏览:1045, 评论:0)
基于delphi的bho开发笔记 (浏览:1631, 评论:0)
阻断弹出式广告的BHO (浏览:1415, 评论:0)
Delphi函数返回多个值 (浏览:1724, 评论:0)
让Sablog也支持Delphi代码高亮功能 (浏览:1820, 评论:4)
发表评论:( 来了就留个脚印吧!你的参与是我最大的动力!)

    

(单击图片换张图片)