在 C# 中检查文件是否隐藏

csharpprogrammingserver side programming更新于 2025/9/23 17:30:00

要检索文件的属性,请使用 FileAttributes 枚举。它有各种成员,如压缩、目录、隐藏等。

要检查文件是否隐藏,请使用隐藏成员名称。

如果设置了 FileAttributes.hidden,则表示文件已隐藏。首先,获取查找属性的路径。

FileAttributes attributes = File.GetAttributes(path);

如果设置了以下内容,则表示文件现在使用隐藏成员名称隐藏。

 File.SetAttributes(path, File.GetAttributes(path) | FileAttributes.Hidden);
Console.WriteLine("The {0} file is hidden.", path);

相关文章