10-11-2024, 01:17 PM
In general the only sure way to check if a filesystem operation is allowed is to do it and be prepared to catch the error. You could maybe try change into every directory immediately to test each one and thus filter the list presented to the user, but I think it's more confusing to see a list that has some entries mysteriously missing. An "access denied" or similar message would be perfectly acceptable to me when I open a directory (cf Windows Explorer, most other file managers).
In any case you need the error handling whenever doing filesystem operations because you don't know what other programs are also modifying the disk concurrently.
At least in Unix systems the root directory has the special property that the parent ".." is also the root, so if you do CHDIR ".." and _CWD$ you must have been in the root. I assume that holds true for windows too. Or just have an OS conditional and check _CWD$ for "/" or "C:" (or is it "C:\"?).
In any case you need the error handling whenever doing filesystem operations because you don't know what other programs are also modifying the disk concurrently.
At least in Unix systems the root directory has the special property that the parent ".." is also the root, so if you do CHDIR ".." and _CWD$ you must have been in the root. I assume that holds true for windows too. Or just have an OS conditional and check _CWD$ for "/" or "C:" (or is it "C:\"?).