我想在C#中查找文件夹中的所有不可见文件。我可以枚举文件
var files = from file in
Directory.EnumerateFiles(@"c:\", "*.txt", SearchOption.AllDirectories)
select new
{
File = file
};
答案 0 :(得分:1)
您可以使用FileInfo类检查文件属性:
FileInfo f = new FileInfo(path);
if ((f.Attributes & FileAttributes.Hidden) != 0)
答案 1 :(得分:-2)
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);
}