怎样通过DirectoryInfo.Attributes获取目录的属性

newpant 2003-10-21 08:30:11
我想通过判断DirectoryInfo.Attributes=FileAttributes.Hidden来判断目录是否是隐藏的,但判断不出来,那个目录是隐藏但是这个判断为FALSE

这该怎么写?

Help Me
...全文
198 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
xixigongzhu 2003-10-21
  • 打赏
  • 举报
回复
文件和目录的属性是多样的,就是几个属性的结合。所以FileAttributes这个枚举的每一位都代表一个意义,如果文件的属性包含某个FileAttribute枚举所代表的位,那么它就有这个FileAttribute枚举所代表的属性。比如如果要判断某个目录是否为隐藏,就要先确定这个目录的属性里是否含有隐藏所表示的位:
(DirectoryInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden
rgbcn 2003-10-21
  • 打赏
  • 举报
回复
The DirectoryInfo class offers a reasonable set of methods for creating, deleting, moving, and so on. For instance, we could create a new directory at some arbitrary location. (In the following example, the new directory is created within the current directory.) We could then create a subdirectory within the new directory, set and then get some attributes, and finally delete both the subdirectory and the newly created parent directory:

dir = new DirectoryInfo("Foo");
if (false == dir.Exists)
dir.Create();

DirectoryInfo dis = dir.CreateSubdirectory("Bar");
dis.Attributes |= FileAttributes.Hidden | FileAttributes.Archive;

Console.WriteLine("{0,-10}{1,-10}{2}",
dis.Name, dis.Parent, dis.Attributes);

dis.Delete(true);
dir.Delete(true);

The output follows:

Bar Foo Hidden, Directory, Archive

saucer 2003-10-21
  • 打赏
  • 举报
回复
try


if( file.Attributes & FileAttributes.Hidden ==
FileAttributes.Hidden )
{

}

110,499

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧