//删除整个文件夹及其下的所有文件
function DelDirAll(aDir: string): Boolean;
var
vSearch: TSearchRec;
vRet: integer;
vKey: string;
begin
if aDir[Length(aDir)] <> ‘\‘ then
aDir := aDir + ‘\‘;
vKey := aDir + ‘*.*‘;
vRet := FindFirst(vKey, faanyfile, vSearch);
while vRet = 0 do
begin
if ((vSearch.Attr and fadirectory) = fadirectory) then
begin
if (vSearch.Name <> ‘.‘) and (vSearch.name <> ‘..‘) then
DelDirAll(aDir + vSearch.name);
end
else
begin
if ((vSearch.Attr and fadirectory) <> fadirectory) then
begin
{System.Sysutils.}DeleteFile(aDir + vSearch.name);
end;
end;
vRet := FindNext(vSearch);
end; //while
{System.SysUtils.}FindClose(vSearch);
Removedir(aDir); // 如果需要删除文件夹则添加
result := True;
end;