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 idhttp post json

Delphi: ttreeview 中禁止双击事件展开或关闭节点

Delphi jpg和bitmap互转转换的方法

Delphi 得到文件创建时间,修改时间,访问时间

Delphi程序中使用自定义的鼠标

Delphi xe5 android openurl

Delphi 长文件路径转换短文件路径

Delphi idhttp控件学习(图片下载)

Delphi webbrowser1 设置获取编码

Delphi streamtohexstr

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



打赏

取消

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

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

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

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

评论

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