c# 检查目录是否隐藏?

发布于 2024-09-16 09:48:46 字数 438 浏览 1 评论 0原文

可能的重复:
如何测试 C# 中目录是否隐藏?

DirectoryInfo dir = new DirectoryInfo(@"c:\test");
if ((dir.Attributes & FileAttributes.Hidden) == (FileAttributes.Hidden)) 
{ 
     //do stuff
}

通过这个 if 语句我想测试该目录是否被隐藏。虽然目录确实是隐藏的,但我的程序没有进入执行操作,因为只设置了属性的目录标志。 有什么建议吗?

Possible Duplicate:
How to test if directory is hidden in C#?

DirectoryInfo dir = new DirectoryInfo(@"c:\test");
if ((dir.Attributes & FileAttributes.Hidden) == (FileAttributes.Hidden)) 
{ 
     //do stuff
}

With this if statement i would like to test if the directory is hidden. Although the directory really is hidden, my program doesn't get into the do stuff because only the directory flag of the attributes is set.
Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑饮青盏花 2024-09-23 09:48:46

试试这个:

DirectoryInfo dir = new DirectoryInfo(@"c:\test");
if ((dir.Attributes & FileAttributes.Hidden) != 0)
{
   //do stuff
}

Try this:

DirectoryInfo dir = new DirectoryInfo(@"c:\test");
if ((dir.Attributes & FileAttributes.Hidden) != 0)
{
   //do stuff
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文