Something like this should work
var folders = Directory.GetDirectories(@"C:\")
.Where(d => !new DirectoryInfo(d).Attributes.HasFlag(FileAttributes.System | FileAttributes.Hidden));
foreach (string dir in folders)
{
.....
Let me expand on the answer as some people may find it difficult to understand, This will ignore SystemHidden
directrories.
ie:
"C:\\$Recycle.Bin"
"C:\\Documents and Settings"
"C:\\System Volume Information"
If you want to ignore all hidden directories you can simply omit the FileAttributes.System
attribute from the linq statement but this would result in losing directories like ProgramData
in your ListView
which I'm not sure you want.