计算文件夹和子文件夹中的所有文件 [英] Counting all files in folder and subfolder
问题描述
我正在使用Visual Basic,我想计算一个文件夹及其子文件夹中存在的所有文件.
调暗计数器= My.Computer.FileSystem.GetFiles("C:\ Folder")MsgBox(文件数为"& CStr(counter.Count))
,但它仅计数 C:\ Folder 中的文件,而不计数 C:\ Folder \ Sub-Folder \ AnotherSubFolder 中的文件我应该怎么办?谢谢您的帮助!
使用 I am using visual basic and I want to count all the files that exist in a folder and in its subfolders.. I tried this : but it only counts files in the C:\Folder and not in C:\Folder\Sub-Folder\AnotherSubFolder
What should I do?
Thank's for help! Use So you'd just use 这篇关于计算文件夹和子文件夹中的所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! Directory.GetFiles()
定义如下: someString
是您要从其开始的顶级目录"*.*"
是您要匹配的搜索模式.这将获取所有文件.例如,如果只需要文本文件,则可以执行"*.txt"
. SearchOption
枚举有两个选项: AllDirectories
或 TopDirectoryOnly
(如果您仅对确切目录感兴趣)通过了,很明显.Dim counter = My.Computer.FileSystem.GetFiles("C:\Folder")
MsgBox("number of files is " & CStr(counter.Count))
Directory.GetFiles()
as defined here: https://msdn.microsoft.com/en-us/library/ms143316(v=vs.110).aspxDim counter As Integer = Directory.GetFiles(someString, "*.*", SearchOption.AllDirectories).Length;
MsgBox("Number of files is : " + counter)
someString
being the top-level directory you want to start at"*.*"
being the search pattern you want to match. This gets all files. If you wanted only text files, for example, you could do "*.txt"
.SearchOption
enum has two options: AllDirectories
or TopDirectoryOnly
if you're only interested in the exact directory passed, obviously.