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 增加/获得windows用户帐号

Delphi 内存管理[6]

Delphi隐藏系统托盘tray图标

Delphi 安卓开发 ioutils文件说明

Delphi 获取鼠标坐标大全方法

Delphi tfilestream 打开模式与共享模式

Delphi 极速字符串替换函数字符串转16进制

Delphi将字符串转换成utf8编码的函数

Delphi如何获取系统服务(即service服务程序)列表

Delphi 中流的使用通过内存流读取文件

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



打赏

取消

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

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

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

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

评论

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