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 获取cpu使用单元文件

Delphi中文件名函数-路径、名称、子目录、驱动器、扩展名

Delphi 正确得到本地ip

Delphi 使用fastscript调试脚本

Delphi html转义

Delphi win10系统已管理员的权限运行应用程序

Delphi只获取文件名(不带扩展名)

Delphi 读取全网站链接

Delphi 如何获取进程的全路径名

Delphi中使用tlist类的简单分析

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



打赏

取消

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

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

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

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

评论

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