function DeleteTree(sPath:string):Boolean;<br>var<br> SearchRec: TSearchRec;<br>begin<br> FindFirst(sPath+'/*.*',faAnyFile,SearchRec);<br> repeat<br> if(SearchRec.Attr and faDirectory > 0) then<br> begin<br> if(SearchRec.Name[1]<>'.') then<br> if not DeleteTree(sPath+'/'+SearchRec.Name) then<br> break;<br> end else //如果是文件直接删除<br> if not DeleteFile(sPath+'/'+SearchRec.Name) then<br> break ;<br> until (FindNext(SearchRec)<>0); //继续查找,直到最后<br> FindClose(SearchRec);<br> Result:=ReMoveDir(sPath);<br>end;<br><br>function DelTree(HW:THandle; sPath:string):boolean;<br>var<br> lpFileOp: TSHFileOpStruct;<br>begin<br> Result:=False;<br> with lpFileOp do<br> begin<br> Wnd := HW;<br> wFunc := FO_DELETE;<br> pFrom := pchar(sPath+#0); //此为要删除的文件或目录,支持*、?<br> pTo := nil;<br> fFlags := FOF_ALLOWUNDO;<br> hNameMappings := nil;<br> lpszProgressTitle := nil;<br> fAnyOperationsAborted := True;<br> end;<br> if SHFileOperation(lpFileOp)=0 then<br> Result:=True;<br>end;<br>