Enumerate Hidden Directories in .NET 4.0

In one of my previous posts, I had discussed 7 New methods to Enumerate Directory and Files in .NET 4.0.

Let us see a practical example of using the DirectoryInfo.EnumerateDirectories to list the names of only hidden directories in a drive.


static void Main(string[] args)
// dir is a collection of IEnumerable<string>
var dir = new DirectoryInfo(@"C:\")
.Where(x => x.Attributes.HasFlag(FileAttributes.Hidden))
.Select(x => x.Name);

foreach (var file in dir)



Shared Sub Main(ByVal args() As String)
' dir is a collection of IEnumerable<string>
Dim dir = New DirectoryInfo("C:\")_
.Where(Function(x) x.Attributes.HasFlag(FileAttributes.Hidden))_
.Select(Function(x) x.Name)

For Each file In dir
Next file

End Sub



About The Author

Suprotim Agarwal
Suprotim Agarwal, Developer Technologies MVP (Microsoft Most Valuable Professional) is the founder and contributor for DevCurry, DotNetCurry and SQLServerCurry. He is the Chief Editor of a Developer Magazine called DNC Magazine. He has also authored two Books - 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook.

Follow him on twitter @suprotimagarwal.

No comments: