DelphiAaron
Programmer
doen anyone have a snippet of code to delete all files and folders from a temp folder, including folders that have files in them.
thanx
Aaron
thanx
Aaron
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
procedure m_deltree(filepath: TFileName);
var
tfileinfo: TSearchRec;
r: TFileName;
retcode: longint;
atribute: word;
begin
r := filepath + '\*.*';
writeln(r);
retcode := 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
m_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(filepath + '\' + tfileinfo.name) = false then
writeln('Error deleting ', filepath + '\' + tfileinfo.name);
end;
retcode := FindNext(tfileinfo);
end;
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
writeln('Error removing ', filepath);
end;
uses ShellAPI;
Function DelTree(DirName : string): Boolean;
var
SHFileOpStruct : TSHFileOpStruct;
DirBuf : array [0..255] of char;
begin
try
Fillchar(SHFileOpStruct,Sizeof(SHFileOpStruct),0) ;
FillChar(DirBuf, Sizeof(DirBuf), 0 ) ;
StrPCopy(DirBuf, DirName) ;
with SHFileOpStruct do begin
Wnd := 0;
pFrom := @DirBuf;
wFunc := FO_DELETE;
fFlags := FOF_ALLOWUNDO;
fFlags := fFlags or FOF_NOCONFIRMATION;
fFlags := fFlags or FOF_SILENT;
end;
Result := (SHFileOperation(SHFileOpStruct) = 0) ;
except
Result := False;
end;
end;
uses JCLFileUtils;
DeleteDirectory (Path: string, MoveIntoRecycleBin: boolean);