C# - 获取不包括隐藏文件的文件列表 [英] C# - Get a list of files excluding those that are hidden

查看:134
本文介绍了C# - 获取不包括隐藏文件的文件列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Directory.GetFiles()返回所有文件,甚至标记为隐藏的文件。有没有办法获取排除隐藏文件的文件列表?

Directory.GetFiles() returns all files, even those that are marked as hidden. Is there a way to get a list of files that excludes hidden files?

推荐答案

这应该适合你:

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

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

foreach (var f in filtered)
{
    Debug.WriteLine(f);
}

这篇关于C# - 获取不包括隐藏文件的文件列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆