Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Exclude protected Operating system files in search

(Using windows 7 64bit and C#)

Is there any way to exclude these protected files from your search?

This is Showing ALL the files in the folder including the "System Files"

string[] files = Directory.GetFiles(directory);

enter image description hereenter image description here

like image 712
Ruan Avatar asked Dec 09 '22 16:12

Ruan


2 Answers

var list = new DirectoryInfo(@"C:\").GetFiles()
                .Where(f => !f.Attributes.HasFlag(FileAttributes.System))
                .Select(f => f.FullName)
                .ToList();
like image 187
I4V Avatar answered Dec 11 '22 07:12

I4V


You can use FileInfo.

var fileInfo = new FileInfo(path);
if((fileInfo.Attributes & FileAttributes.System) != FileAttributes.System))
{
    // path is not a system file
}
like image 25
esskar Avatar answered Dec 11 '22 07:12

esskar