I am writing some code to access directories and index the files it finds. The user is able to enter a UNC path and impersonate another user to get access to that directory. I am using Directory.Exists to see if the path they have entered is valid before trying to access it.
This works fine for local paths, but when trying to access a UNC path that I know I don’t have access to, Directory.Exists is returning true.
My understanding is then that Directory.Exists does not check if the particular path can be “accessed” just that it exists or not.
What else can I use to check if a directory exists and I have read access to it ?
I don’t know any of the file names inside the directory at this point.
Thanks!
Why not simply attempt to perform your indexing by enumerating the files and handle the exception generated when its unable to access? There is always a possibility that a sub-folder or an individual file may not be accessible anyway even if you access the specific directory given.