Checking file/folder access permission

前端 未结 3 1258
故里飘歌
故里飘歌 2020-11-27 22:15

I get an UnautorizedAccessException running this code:

string[] fileList = Directory.GetFiles(strDir, strExt);

The exception o

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-27 22:59

    First, call Directory.GetFiles for root directory. Catch UnauthorizedAccessException - if none, you have full access.

    If caught - call the function for each subdir recursively, catch the exception, if caught - add such dir to list.

    Write a recursive function with external list for forbidden dirs

提交回复
热议问题