如何在Windows 8.1 C#中获取本地文件夹大小 [英] How do I get local folder size in windows 8.1 C#

查看:88
本文介绍了如何在Windows 8.1 C#中获取本地文件夹大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我想知道本地文件夹大小。(例如210 MB)


$ b $例如,b我有一个应用程序将一些内容下载到我的本地文件夹,我想检查我的本地文件夹的大小有多少MB的GB。







我怎么能得到它。在Windows 8.1 ..?







我曾尝试使用MSDN和谷歌但是没有线索。











谢谢,



-Jitendra Jadav。

Hello,

I wanted to know Local Folder Size.?(e.g. 210 MB)

for e.g. I have an application which would download some of the content into my local folder and I want to check the size of my local folder how much MB of GB is there.



How I could get it. in windows 8.1..?



I have tried with MSDN and google also but there is no clue.





Thank you,

-Jitendra Jadav.

推荐答案

你必须使用递归方法来计算当前文件夹中每个文件的大小,并为每个子文件夹调用相同的方法。



在此方法中查找当前文件夹的子项,您应该使用Directory.GetDirectories()方法,并查找可以使用的文件大小FileInfo类(这两个类都来自System.IO名称空间)。
You have to use a recursive method that calculate the size of each file from the current folder and invoke the same method for each subfolder.

In this method to find the sub-items of the current folder you should use Directory.GetDirectories() method, and to find the size of a file you can use FileInfo class (both classes are from System.IO namespace).


使用此方法获取所有文件名: http://msdn.microsoft.com/en-us/library/ms143316%28v=vs.110%29.aspx [< a href =http://msdn.microsoft.com/en-us/library/ms143316%28v=vs.110%29.aspxtarget =_ blanktitle =New Window> ^ ] 。



您不需要自己使用递归;此方法允许您获取目录中的所有文件。使用 SearchOption.AllDirectories

http://msdn.microsoft.com/en-us/library/ms143448%28v=vs.110%29.aspx [ ^ ]。



您需要的大小将是所有文件大小的总和。这是你如何获得每个文件的大小:

http://msdn.microsoft.com/en-us/library/system.io.fileinfo.length%28v=vs.110%29.aspx [<一个href =http://msdn.microsoft.com/en-us/library/system.io.fileinfo.length%28v=vs.110%29.aspxtarget =_ blanktitle =New Window> ^ ],

http://msdn.microsoft.com/en-us/library/System.IO.FileInfo%28v=vs.110%29.aspx [ ^ ]。



-SA
Use this method to get all file names: http://msdn.microsoft.com/en-us/library/ms143316%28v=vs.110%29.aspx[^].

You don't need to use recursion by yourself; this method allows you to get all files in the directory. Use SearchOption.AllDirectories:
http://msdn.microsoft.com/en-us/library/ms143448%28v=vs.110%29.aspx[^].

The size you need will be the sum of the sizes of all files. This is how you can get the size for each file:
http://msdn.microsoft.com/en-us/library/system.io.fileinfo.length%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/System.IO.FileInfo%28v=vs.110%29.aspx[^].

—SA


这篇关于如何在Windows 8.1 C#中获取本地文件夹大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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