Old-Style , but you do not delete inside deep-all-subdirs.
Function SHFileOperation_FO_DELTREE(filepath: h_types.TFileName3):string;
var
tfileinfo: TSearchRec;
r: TFileName;
retcode,atribute: longint;
begin
result:='';
r := filepath + '\*';
writeln(r);
retcode := SysUtils.FindFirst(r, faAnyFile - faVolumeID, tfileinfo);
while retcode = 0 do
begin
if (tfileinfo.attr and faDirectory = faDirectory) then
begin
if (tfileinfo.name <> '.') and (tfileinfo.name <> '..') then
result:=concat(result,SHFileOperation_FO_DELTREE(filepath + '\' + tfileinfo.name));
end
else
begin
atribute := tfileinfo.attr;
atribute := atribute and not faReadOnly;
atribute := atribute and not faArchive;
atribute := atribute and not faSysFile;
atribute := atribute and not faHidden;
FileSetAttr(filepath + '\' + tfileinfo.name, atribute);
if DeleteFile(pchar(filepath + '\' + tfileinfo.name)) = false then
result:=concat(result,filepath + '\' + tfileinfo.name,#13#10);
end;
retcode := SysUtils.FindNext(tfileinfo);
end;
SysUtils.FindClose(tfileinfo);
atribute := FileGetAttr(filepath);
atribute := atribute and not faReadOnly;
atribute := atribute and not faArchive;
atribute := atribute and not faSysFile;
atribute := atribute and not faHidden;
FileSetAttr(filepath, atribute);
if RemoveDir(filepath) = false then
result:=concat(result,'RMdir ', filepath,' =Failed'#13#10);
end;
Procedure DelFilesFromDir(Const Directory, FileMask: string; DelSubDirs: boolean);
var
SourceLst: string;
FOS: TSHFileOpStruct;
begin
FillChar(FOS, sizeof(FOS), 0);
// FOS.Wnd := Application.MainForm.Handle;
FOS.Wnd := application_handle;
FOS.wFunc := FO_DELETE;
SourceLst := Directory + '\' + FileMask + #0;
FOS.pFrom := pchar(SourceLst);
if not DelSubDirs then
FOS.fFlags := FOS.fFlags OR FOF_FILESONLY;
// Remove the next line if you want a confirmation dialog box
FOS.fFlags := FOS.fFlags OR FOF_NOCONFIRMATION;
// Uncomment the next line for a "silent operation" (no progress box)
// FOS.fFlags := FOS.fFlags OR FOF_SILENT;
SHFileOperation(FOS);
end;