本文整理自网络,侵删。
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 filebegin 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判断mssql数据库中表格是否存在? 如何批量创建表格?
Delphi getprocessisadmin()判断exe是否以管理员身份启动
更多相关阅读请进入《Delphi》频道 >>