function TFtpContentThd.DeleteDirectory(NowPath: string): Boolean; var search: TSearchRec; ret: integer; key: string; begin if NowPath[Length(NowPath)] <> '\' then NowPath := NowPath + '\'; key := NowPath + '*.*'; ret := findFirst(key, faanyfile, search); while ret = 0 do begin if ((search.Attr and fadirectory) = fadirectory) then begin if (search.Name <> '.') and (search.name <> '..') then begin DeleteDirectory(NowPath + search.name); removedir(NowPath + search.name); //如果需要删除文件夹则添加 end; end else begin if ((search.Attr and fadirectory) <> fadirectory) then begin deletefile(PAnsiChar(NowPath + search.name)); end; end; ret := FindNext(search); end; FindClose(search.FindHandle); //FindClose(search); //发现在线程里面不能用这,只能用上面的句柄 //removedir(NowPath); //如果需要删除最外层文件夹则添加 result := True; end;