FUNCTION WritableDir(CONST Dir : STRING) : BOOLEAN; VAR FIL : FILE; N : STRING; I : Cardinal; BEGIN REPEAT N:=IncludeTrailingPathDelimiter(Dir); FOR I:=1 TO 250-LENGTH(N) DO N:=N+CHAR(RANDOM(26)+65) UNTIL NOT FileExists(N); Result:=TRUE; TRY AssignFile(FIL,N); REWRITE(FIL,1) EXCEPT Result:=FALSE END; IF Result THEN BEGIN CloseFile(FIL); ERASE(FIL) END END;
http://blog.csdn.net/genispan/article/details/10004487