2

Possible Duplicate:
How do you check for permissions to write to a directory or file?

I'm trying to figure out if it is possible to determine if a requested file directory is writable and the current user have the right permissions to write into that folder.

Till now I'm making a test for the requested path by creating new directory, writing a temp file into it and remove it (the temp file and directory).

This operation is very problematic since that directory may be exist already and all of its old information can be lost (when the directory remove).

Any idea ?? Tx...


  • The highly upvoted answer in the linked dup is wrong. CAS has nothing to do with operating system permissions. Go for the lowest voted answer ;) - Hans Passant
  • @Hans Passant, Tx for your comment... I'm wondering if that's the best approach for my issue... - Liran Ben Yehuda
  • There are lots of reasons why creating a file might fail, beyond CAS and access rights. You can do the work to test user rights but still have no guarantee. Deal with failure when you actually try to create the file. - Hans Passant
  • Just check the directory does not exist before creating it. Usually the system does not remove a directory until its empty, or unless you use a function that recursively removes all files and directories, and only then removes the directory itself. - Alexey Ivanov
  • Tx you all... I will improve my test.. - Liran Ben Yehuda

1 답변


5

The best approach is to attempt the operation and let the system decide whether or not it is allowed. Duplicating the checks that the system performs would be terribly hard to get right. Just let the system decide, it is the ultimate arbiter.

Linked


Related

Latest