James Cadd James Cadd - 1 year ago 92
C# Question

C# - Get a list of files excluding those that are hidden

returns all files, even those that are marked as hidden. Is there a way to get a list of files that excludes hidden files?

Answer Source

This should work for you:

DirectoryInfo directory = new DirectoryInfo(@"C:\temp");
FileInfo[] files = directory.GetFiles();

var filtered = files.Where(f => !f.Attributes.HasFlag(FileAttributes.Hidden));

foreach (var f in filtered)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download