-2

I want to find all the invisible files in a folder in C#. I can enumerate the files

var files = from file in 
   Directory.EnumerateFiles(@"c:\", "*.txt", SearchOption.AllDirectories)
select new
{
File = file
};
Subha
  • 9
  • 1
  • 1
    Wrong it is not a duplicate, even though the code will slightly change the link you posted is to Exclude Hidden files, this post is about Excluding Visible Files. So the concept is the same but the question differs. – Donald Jansen Feb 10 '16 at 11:04
  • @DonaldJansen - The given duplicate is where the op plagiarised the code from to provide their own answer, how is it not a duplicate? – Sayse Feb 10 '16 at 11:05
  • Because of this line `var filtered = files.Where(f => f.Attributes.HasFlag(FileAttributes.Hidden));` I understand that he might have recieved that code from that link, or anywhere else and then changed it to fit his needs. But thats just my opinion – Donald Jansen Feb 10 '16 at 11:10

2 Answers2

1

You can check for the file attribute using the FileInfo class:

            FileInfo f = new FileInfo(path);
            if ((f.Attributes & FileAttributes.Hidden) != 0)
assyadh
  • 11
  • 1
-2

From a previous SO post

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

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

foreach (var f in filtered)
{
    Debug.WriteLine(f);
}
Community
  • 1
  • 1
Subha
  • 9
  • 1
  • 9
    If you've found a duplicate then you should link to that duplicate, not take credit and plagiarise it. – Sayse Feb 10 '16 at 11:00