Testing if the directory attribute is R / O is only part of the answer. You can easily have an R / W directory that you still cannot write, due to permissions.
The best way to check if you can write to the directory or not is to try:
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); Result:=FileExists(N); // Not sure if this is needed, but AlainD says so :-) EXCEPT Result:=FALSE END; IF Result THEN BEGIN CloseFile(FIL); ERASE(FIL) END END;
Heartware
source share