I'm enumerating all files in a directory so that I can process them later. I want to exclude hidden and system files.
This is what I have so far:
IEnumerable<IGrouping<string, string>> files;
files = Directory.EnumerateFiles(sourcePath, "*", SearchOption.AllDirectories)
.Where(f => (new FileInfo(f).Attributes & FileAttributes.Hidden & FileAttributes.System) == 0)
.GroupBy(Path.GetDirectoryName);
However if I look at the results I am still getting hidden and system files included:
foreach (var folder in files)
{
foreach (var file in folder)
{
// value for file here still shows hidden/system file paths
}
}
I found this question which has a similar example from Jerome but I couldn't even get that to compile.
What am I doing wrong?