[Delphi] 재귀함수를 이용한 폴더 삭제
필요할 때마다 매번 작성하다보니 귀찮은 데다가 시간 아까움.. 별 것도 아닌데 그냥 긁어다 쓰는게 정답.
// pDir 디렉토리, 하위 폴더 및 파일 모두 삭제
procedure RemoveDirectoryAll(pDir: string);
var
TempList : TSearchRec;
begin
if FindFirst(pDir + '\*', faAnyFile, TempList) = 0 then
begin
repeat
if ((TempList.attr and faDirectory) = faDirectory) and not (TempList.Name = '.') and not (TempList.Name = '..') then
begin
if DirectoryExists(pDir + '\' + TempList.Name) then
begin
RemoveDirectoryAll(pDir + '\' + TempList.Name);
end;
end
else
begin
if FileExists(pDir + '\' + TempList.Name) then
begin
DeleteFile(pDir + '\' + TempList.Name);
end;
end;
until FindNext(TempList) <> 0;
end;
if DirectoryExists(pDir) then
RemoveDir(pDir);
FindClose(TempList);
end;