如何在列表框列出的项目中获取总文件夹数?

编程入门 行业动态 更新时间:2024-10-23 04:42:42
本文介绍了如何在列表框列出的项目中获取总文件夹数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

表单中有一个ListBox然后 我在列表框中列出文件夹方式,其中包含FolderBrowserDialog; C:\ Users \Yaman \Desktop\TestA'(有4个文件夹27个文件) C:\ Users \Yaman \Desktop \ TestB' (有5个文件夹30个文件) 当我列出一个再见时,我可以获得文件夹和文件数。 如果我只列出这个; C:\ Users \Yaman \Desktop \ TestA 结果是 27个文件/ 4个文件夹 但是当我列出两个文件夹方式时我可以得到只有最后列出的文件夹计数结果 如果我列出 C:\ Users \Yaman \\ \\Desktop \ TestA C:\ Users \Yaman \Desktop \ TestA 结果最后列为此 30个文件/ 5个文件夹 我如何计算所有文件夹文件和子文件夹的数量一起列在列表框中? 我尝试过: < pre> Private Sub Button11_Click(发件人 As Object ,e As EventArgs) Handles Button11.Click 对于 z = 0 ListBox1。 Items.Count - 1 Dim TheSize As 长 = GetDirSize(ListBox1.Items.Item(z))' (C:\ Users \Yaman \Desktop \ Deneme) Dim counterDir As 整数 = IO.Directory .GetDirectories(ListBox1.Items.Item(z), *。*,IO.SearchOption。 AllDirectories。.Length ' 计算文件数 Dim counterFile As Integer = IO.Directory.GetFiles(ListBox1.Items.Item (z), *。*,IO.SearchOption.AllDirectories).Count 计算文件数 Label5.Text = counterFile& Files& /& counterDir.ToString& 文件夹 下一页 z 结束 Sub

解决方案

检查:

私人 Sub Button11_Click(发件人作为 对象,e As EventArgs)句柄 Button11.Click Dim currpath As String = Dim TheSize 作为 长 = 0 Dim counterFile 作为 整数 = 0 Dim counterDir As 整数 = 0 对于 z = 0 ListBox1.Items.Count - 1 currpath = ListBox1.Items.Item(z).ToString() TheSize = GetDirSize(currpath)' (C:\ Users \Yaman \Desktop\Deneme) counterDir + = IO.Directory.GetDirectories(currpath, *。*,IO.SearchOption.AllDirectories).Length 计算文件数 counterFile + = IO.Directory.GetFiles(currpath, *。*,IO.SearchOption.AllDirectories).Count ' 计算文件数 下一步 z Label5.Text = counterFile& file(s)& span class =code-string> in& counterDir.ToString& 文件夹 结束 Sub

深入了解更改;) 有关详细信息,请参阅:范围Microsoft Docs [ ^ ]

There is an ListBox in the form then I am listing Folders Way in Listbox With FolderBrowserDialog as this ; C:\Users\Yaman\Desktop\TestA '(Has 4 Folders 27 Files) C:\Users\Yaman\Desktop\TestB '(Has 5 Folders 30 Files) I can get the folders and files count when I listed one bye one. if I listed only this ; C:\Users\Yaman\Desktop\TestA in listbox the result is 27 Files / 4 Folders but when I listed both folder way I can get only last listed folders count result if I listed C:\Users\Yaman\Desktop\TestA C:\Users\Yaman\Desktop\TestA then result is last listed as this 30 Files / 5 Folders How can I get all folders files and subfolders count which together listed in listbox ? What I have tried:

<pre>Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click For z = 0 To ListBox1.Items.Count - 1 Dim TheSize As Long = GetDirSize(ListBox1.Items.Item(z)) '("C:\Users\Yaman\Desktop\Deneme") Dim counterDir As Integer = IO.Directory.GetDirectories(ListBox1.Items.Item(z), "*.*", IO.SearchOption.AllDirectories).Length 'counts the number of files Dim counterFile As Integer = IO.Directory.GetFiles(ListBox1.Items.Item(z), "*.*", IO.SearchOption.AllDirectories).Count 'counts the number of files Label5.Text = counterFile & " Files" & " / " & counterDir.ToString & " Folders" Next z End Sub

解决方案

Check this:

Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click Dim currpath As String = "" Dim TheSize As Long = 0 Dim counterFile As Integer = 0 Dim counterDir As Integer = 0 For z = 0 To ListBox1.Items.Count - 1 currpath = ListBox1.Items.Item(z).ToString() TheSize = GetDirSize(currpath) '("C:\Users\Yaman\Desktop\Deneme") counterDir += IO.Directory.GetDirectories(currpath, "*.*", IO.SearchOption.AllDirectories).Length 'counts the number of files counterFile += IO.Directory.GetFiles(currpath, "*.*", IO.SearchOption.AllDirectories).Count 'counts the number of files Next z Label5.Text = counterFile & " file(s)" & " in " & counterDir.ToString & " folder(s)" End Sub

Take a deep look at the changes ;) For further details, please see: Scope in Visual Basic | Microsoft Docs[^]

更多推荐

如何在列表框列出的项目中获取总文件夹数?

本文发布于:2023-07-16 20:14:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1125462.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件夹   项目   如何在   列表

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!