15 Jun

C# Get Hidden Files In A Directory

This example list all hidden files on the specified path.

Code Sample:

            //Suppose we have this sample directory and files

            //C:\TestDirectory\Files\file2.txt //Hidden
            //C:\TestDirectory\Files\file4.txt //Hidden

            string[] filePaths = Directory.EnumerateFiles(@"C:\TestDirectory\Files\").
                                           Where(f => (new FileInfo(f).Attributes & FileAttributes.Hidden) == FileAttributes.Hidden).
            foreach (string file in filePaths)

2 thoughts on “C# Get Hidden Files In A Directory

  1. Hello thanks for sharing the information.

    I am a newbie computer programming student and have a lab work. Whatever I need to move a folder with all the sub folders and files to a target path. I could not accomplish, can you help me.

    Thanks in advance.

  2. You can use “Move” method in System.IO.Directory class.

    Sample usage:
    Directory.Move(@”C:\SourceDirectory”, @”C:\DestinationDirectory”);

Leave a Reply

Your email address will not be published. Required fields are marked *