获取目录中某些文件类型的大小... [英] Get the size of certain file types in a directory...

查看:60
本文介绍了获取目录中某些文件类型的大小...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这一行代码中,我获得了用户cookie文件夹中的文件数量和文件夹的大小,并将它们显示在标签中:

In this line of code, I get the amount of files in the user''s cookies folder and the size of the folder, and display them in a label:

Label1.Text = (" - " + CStr(cookiecounter.Count) + " cookies (" + (cookiefoldersize / 1000 / 1000).ToString("0.00") + " MB)")



它没有给出我想要的结果...它显示了文件夹的总大小.我希望它显示文件夹中* .txt文件总数的大小.



It doesn''t give the results that I want... it shows the total size of the folder. I want it to show the size of the total amount of *.txt files in the folder. Is there a way to do this?

推荐答案

我不好,它实际上是DirectoryInfo及其GetFiles方法.

My bad, it''s actually DirectoryInfo and it''s GetFiles method.

Dim rootFolder As DirectoryInfo("C:\somePath")
Dim txtFiles() As FileInfo

txtFiles = rootFolder.GetFiles("*.txt")



然后,简单地枚举txtFiles集合并添加每个FileInfo对象的Length属性.



Then it''s a simple matter of enumerating over the txtFiles collection and adding up the Length properties of each FileInfo object.


您将必须使用Directory类来获取列表.用户cookie文件夹中的.TXT文件(显然,首先您必须确定该文件夹的路径是!),然后只需将所有大小加起来即可.
You''ll have to use the Directory class to get the list of .TXT files in the users cookie folder (first you have to determine what the path to that folder is, obviously!) then you can just add up all the sizes.


这篇关于获取目录中某些文件类型的大小...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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