delphi 快速删除非空文件夹


本文整理自网络,侵删。

 procedure DeleteDir(sDirectory: String); 
//删除目录和目录下得所有文件和文件夹
var
sr: TSearchRec;
sPath,sFile: String;
begin
//检查目录名后面是否有 '\'
if Copy(sDirectory,Length(sDirectory),1) <> '\' then
sPath := sDirectory + '\'
else
sPath := sDirectory;

//------------------------------------------------------------------
if FindFirst(sPath+'*.*',faAnyFile, sr) = 0 then
begin
repeat
sFile:=Trim(sr.Name);
if sFile='.' then Continue;
if sFile='..' then Continue;

sFile:=sPath+sr.Name;
if (sr.Attr and faDirectory)<>0 then
DeleteDir(sFile)
else if (sr.Attr and faAnyFile) = sr.Attr then
DeleteFile(sFile); //删除文件
until FindNext(sr) <> 0;
FindClose(sr);
end;
RemoveDir(sPath);
//------------------------------------------------------------------
end;

相关阅读 >>

Delphi 瞬间消除无用托盘图标(刷新托盘)

Delphi2007-Delphi2010 程序不出现在任务栏的方法

Delphi tlog 日志

Delphi 用nethttpclient执行post操作遇到的问题

Delphi多级指针

Delphi tadodataset 加载数据到fdmemtable1

Delphi 双击listbox1内容,数据插入到memo1/synedit1鼠标指定位置

Delphi reset 以只读方式打开文件

Delphi 如何解析网址?

Delphi webbrowser获取iframe页面内容

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...