I'm loading a treeview with directories and it's sub directories. My call to:
string[] dirs = Directory.GetDirectories(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
returns all the directories i want and some i do not... like the inaccessible/virtual 'My Music', 'My Videos', etc...I of course cannot do any recursion in these directories due to the Library structure (Access denied)...
How can i avoid populating these inaccessible directories? I could iterate through the array and remove the unwanted directories if the OS is Vista or 7 and leave be for XP... but i wanted to know if there is a more 'elegant' solution to this?
with Wim's help i came up with this:
private List<string> MyDocuments()
{
List<string> dirs = new List<string>(Directory.GetDirectories(
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)));
for (int i = 0; i < dirs.Count-1; i++)
{
DirectoryInfo di = new DirectoryInfo(dirs[i]);
if (di.Attributes.HasFlag(FileAttributes.ReparsePoint))
dirs.RemoveAt(i);
}
return dirs;
}