如何计算根驱动器中的所有目录? [英] How to count all directories in root drive?
本文介绍了如何计算根驱动器中的所有目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,为什么我的标签不计算C:\
中的所有目录和子目录,我有些困惑
我不希望计数文件,我只想对我选择的驱动器中的所有现有文件夹进行快速计数.
这是我到目前为止的内容:
Hello I am a bit stuck as to why my label will not count all the directories and sub directories in C:\
I do not wish to count the files, I only wish to get a quick count for all existing Folders in which ever drive I choose.
Here is what i have so far:
Try
Dim Root As New DirectoryInfo("SearchPath eg. C:\")
Dim Dirs As DirectoryInfo() = Root.GetDirectories("*.*", SearchOption.AllDirectories)
Dim count As Integer = Dirs.Length
For Each DirectoryName In Dirs
Label12.Text = count
Next
Catch ex As UnauthorizedAccessException
End Try
如果尝试以此加载程序,则会收到一条路径访问冲突消息,指出文档和设置受到保护.
一个快速的例子将不胜枚举,或者解释为什么它不起作用将是同样的.
If I try to load the program with this I get a path access violation saying documents and settings is protected.
A quick example would be greatly appricated or an explaination of why this does not work would be just as equal.
thank you in advance!!
推荐答案
请改用Directory.GetDirectories("c:\")
.
此外,DirectoryInfo
采用有效路径,因此应为DirectoryInfo("C:\")
.
UseDirectory.GetDirectories("c:\")
instead.
AlsoDirectoryInfo
takes a valid path, so it should beDirectoryInfo("C:\")
.
这篇关于如何计算根驱动器中的所有目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文