计数要标记的当前目录? [英] Count Current Directory To Label?

查看:47
本文介绍了计数要标记的当前目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的程序遍历文件系统时,我需要一些帮助计算文件夹和子文件夹的信息.

我已经看到了许多关于如何计算文件夹内文件数量的示例,但我只希望为迭代器所经过的每个新目录的计数增加+1.

我希望我的问题很清楚,希望有人可以帮助我

好的,这是我到目前为止使用的代码,但是它一次返回所有目录和子目录计数,而不是一个接一个地计数.


I need a bit of help counting folders and subfolders while my program iterates through the filesystem.

I have seen many examples of how to count files inside of folders but I only wish to add +1 to a count for each new directory the iterator travels through.

I hope my question is clear enough and that someone can help me

Ok this is the code I am using thus far but it returns all directory and sub directory counts all at once and not one by one.


Public Function CountDirectories(ByVal dir As DirectoryInfo) As Integer
            Try
                Dim MySubdirs() As DirectoryInfo = dir.GetDirectories()
                Dim count As Integer = MySubdirs.Length
                For Each subDir As DirectoryInfo In MySubdirs
                    count += CountDirectories(subDir)
                Next subDir
                Return count
            Catch ex As Exception
            End Try
        End Function  




然后,我可以使用以下方法将其显示在标签上:





Then I am able to show that count to a label by using:


Dim MyDirectoryInfo As New DirectoryInfo(pathToSearchCombo.Text)
           Dim Mytotalcount As Integer = CountDirectories(MyDirectoryInfo)
           Label12.Text = Mytotalcount  



我正在寻找一种方法,当我的程序迭代文件系统时,该方法将返回一个逐个计数的文件夹.

谢谢,很抱歉,如果这很简单,我想不起来怎么办?
谢谢你
干杯!



I am looking for a method that will return a folder count one by one while my program iterates the filesystem.

thank you and sorry if this is simple I just cannot think of how??
thank you
cheers!

推荐答案

这样做与计数文件夹中的文件完全相同.您只需在文件夹中获取目录,而不是文件即可.

在没有看到用于计数文件的代码的情况下,很难准确地告诉您要更改的内容.
This is done the exact same way as counting the files in a folder. You just get the directories in the folder instead of the files.

Without seeing the code you''re using to count the files, it''s difficult to tell you exactly what to change.


这篇关于计数要标记的当前目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆