Delphi DeleteFiles 删除目录下多个文件


本文整理自网络,侵删。

 
function DeleteFiles(const Dir, Wildcard: string): Integer;
var
  Files: TStringList; // stores files to be deleted
  I: Integer;         // loops thru files in folder
  AFile: string;      // a file to be deleted
  Attr: Integer;      // attributes of a file
begin
  Result := 0;
  Files := TStringList.Create;
  try
    // Get matching list of files / folders in directory
    if not ListFiles(Dir, Wildcard, Files) then
      Exit;
    for I := 0 to Pred(Files.Count) do
    begin
      AFile := Files[I];
      Attr := FileGetAttr(AFile);
      // Delete file if it is not a directory
      if (Attr and faDirectory = 0) then
      begin
        if SysUtils.DeleteFile(AFile) then
          // File deleted: count it
          Inc(Result);
      end;
    end;
  finally
    FreeAndNil(Files);
  end;
end;

相关阅读 >>

Delphi判断线程是否正在运行

Delphi 排列桌面图标

Delphi中控制扫描仪

Delphi 反外挂,反破解思想代码

Delphi控制程序在任务栏显示与隐藏

Delphi 10.2 ide界面

Delphi 修改webbrowser的内容

firemonkey使用android的路径信息

Delphi判断mssql数据库中表格是否存在? 如何批量创建表格?

Delphi getprocessisadmin()判断exe是否以管理员身份启动

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



打赏

取消

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

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

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

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

评论

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

    暂无评论...