I want a safe way to get all of the files nested under the user folder (nominally C:\Users\TheUsersName
). The problem is that most of the folders there are reparse points, so just iterating/recursing over the folder's folders will not return those folders, and therefore not the files under them as well.
The simple but unwanted solutions would be either to
- hard code those folders. - never a good idea. What if in the future a new one is added or one removed.
- for the UserProfile folder only, retrieve the folders that any reparse points under it point to. - not safe - may become cyclic.
So to sum up: is there any safe way to get all files under the user folder including those nested under the reparse points there?
Since (judging by the comments) it seems like this isn't clear. I'll state this explicitly:
I don't want to get the targets of the reparse points. Not even only in the specific case of UserProfile. Because there might be one pointing to UserProfile itself or a folder that contains it. I want some list of the normal (though not 'real') folders that are there like 'Documents' (which I would assume would not point to a folder that contains the UserProfile and therefore would not become cyclic). Or some other clean solution.
DirectoryInfo
. The problem is that that folder's "folders" are not all real folders. From the docs "The .NET Framework methods such as GetFiles and GetDirectories will not return any subdirectories under a reparse point. ". (That's a good thing.)