在 C# .Net 2.0 中使用文件属性
那么我如何递归搜索文件夹并取消隐藏目录中的所有文件和子文件夹?就像让它检查每个文件和每个文件夹......如果它们被隐藏......取消隐藏它们。我整个早上都在摆弄它,但没有运气……我把所有文件夹都设置回正常状态,但仅此而已。
So how can i recursively search a Folder and un-hide ALL files and sub folders in a directory? Like have it check each file and each folder... if they're hidden.. un-hide them. Iv been messing around with it all morning with no luck... i got all folders to set back to normal but thats about it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要递归地执行此操作,
也使用包含目录,请使用 <代码>GetFileSystemEntries
to do it recursively, use
to include directories too, use
GetFileSystemEntries
像这样的事情怎么样?
How about something like this?
使用递归可以轻松解决这个问题。
文件属性(例如“隐藏”)被指定为枚举标志,并且使用 bit 最容易设置或清除操作。您可以通过获取 FileInfo 或该路径的 DirectoryInfo。
现在,您可以通过调用递归地取消隐藏目录中的所有隐藏文件
当然,当您使用此代码时,您将希望删除对
Console.WriteLine
的所有调用,但我将它们留在那里以便更容易您可以看到代码运行时发生了什么。这是一个更简洁的版本:This is easily solved using recursion.
File attributes such as "hidden" is specified as an enum flag and is most easliy set or cleared using bit operations. You can see a file or directory's attributes by getting a FileInfo or DirectoryInfo for that path.
You can now recursively unhide all hidden files inside a directory by calling
Of course, you'll want to remove all calls to
Console.WriteLine
when you use this code but I left them there to make it easier for you to see what's going on when the code is running. Here's a more condense version: