I want to know how to get only hidden folder from String[]. Actually I have one string array and there show some files. There have normal and hidden files also but I want to try
You can test whether a directory is hidden by checking Attributes
property of the DirectoryInfo
class:
var info = new DirectoryInfo(path);
var hidden = info.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden
The same code would work for testing whether a file is hidden, but you'd use FileInfo
instead of DirectoryInfo
. It is not clear what your array contains and what do you want to get, but generally, you could use LINQ to implement filtering. The following returns a new collection containing only hidden directories:
var hiddenDirectories = allDirectories.Where(path => {
var info = new DirectoryInfo(path);
var hidden = (info.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden
return hidden; });
You should be able to adapt this to your needs (depending on what files/directories you want to get as the result).
Create FileInfo
object for each file and the use its Directory
property to get a DirectoryInfo
instance on which you can check the Attributes
property that will tell you if the directory is hidden.