I list all the files in the 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 still get the hidden and system files:
foreach (var folder in files)
{
foreach (var file in folder)
{
}
}
I found this question that has a similar example from Jerome, but I could not even compile it.
What am I doing wrong?
source
share