再来一个:copy from RxLib - FileUtil.pas<br>function ClearDir(const Path: string; Delete: Boolean): Boolean;<br>const<br>{$IFDEF WIN32}<br> FileNotFound = 18;<br>{$ELSE}<br> FileNotFound = -18;<br>{$ENDIF}<br>var<br> FileInfo: TSearchRec;<br> DosCode: Integer;<br>begin<br> Result := DirExists(Path);<br> if not Result then Exit;<br> DosCode := FindFirst(NormalDir(Path) + '*.*', faAnyFile, FileInfo);<br> try<br> while DosCode = 0 do begin<br> if (FileInfo.Name[1] <> '.') and (FileInfo.Attr <> faVolumeID) then<br> begin<br> if (FileInfo.Attr and faDirectory = faDirectory) then<br> Result := ClearDir(NormalDir(Path) + FileInfo.Name, Delete) and Result<br> else if (FileInfo.Attr and faVolumeID <> faVolumeID) then begin<br> if (FileInfo.Attr and faReadOnly = faReadOnly) then<br> FileSetAttr(NormalDir(Path) + FileInfo.Name, faArchive);<br> Result := DeleteFile(NormalDir(Path) + FileInfo.Name) and Result;<br> end;<br> end;<br> DosCode := FindNext(FileInfo);<br> end;<br> finally<br> FindClose(FileInfo);<br> end;<br> if Delete and Result and (DosCode = FileNotFound) and<br> not ((Length(Path) = 2) and (Path[2] = ':')) then<br> begin<br> RmDir(Path);<br> Result := (IOResult = 0) and Result;<br> end;<br>end;<br>