Recursively search directories in C #
You will need to check permissions, but I would highly recommend throwing exceptions instead, which makes the code clearer and will also deal with other issues, like when you want to parse directories remotely and the network stops working ...
If you are building a GUI for a directory tree, you can also add some nice lock icons in places where you get error permissions and error icons elsewhere ... C # already has a nice free open source component for this.
If you want to count files and sizes, there is no way to fix the permissions issue, you must run your tool under a more privileged user.
source to share
I looked at your link and code. In the sample code, the try ... catch construct is used to stop the search when you enter a folder that you do not have permission to.
So, based on this, my understanding of your question can be phrased as "How can I know if I have permission to read the folder without trying to read the folder and throwing an exception if I don't have permission?"
If so, then this related post will probably be helpful to you.
Checking write permissions to directory and file in .NET
Added
I agree with @ jdehaan's answer, but only after reading the link I posted for recommendation reason.
source to share