James Cadd James Cadd - 5 months ago 41
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?


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)