在asp.net中查找文件夹大小 [英] Find folder size in asp.net

查看:61
本文介绍了在asp.net中查找文件夹大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在其子目录中找到特定文件夹的大小,并希望将其打印到asp.net中的标签上……任何人都可以帮助我吗???在adv中使用thnx ...

I want to find perticular folder size with it''s sub directories, and want to print it to the label, in the asp.net... can any one help me out??? Thnx in adv...

推荐答案

请看下面的链接.

http://msdn.microsoft.com/en-us/library/system.io. directory.aspx
Have a look at below link.

http://msdn.microsoft.com/en-us/library/system.io.directory.aspx


使用这些代码
use these code
protected void Page_Load(object sender, EventArgs e)
{
    Response.Write(FindFolderSize(new DirectoryInfo(Server.MapPath("~")), UnitType.KB, 0).ToString() + " KB");
    Response.Write(FindFolderSize(new DirectoryInfo(Server.MapPath("~")), UnitType.MB, 2).ToString() + " MB");
    Response.Write(FindFolderSize(new DirectoryInfo(Server.MapPath("~")), UnitType.GB, 5).ToString() + " GB");
}



公共枚举UnitType {KB = 1,MB = 2,GB = 3}
///
///查找文件夹大小
///
///目标文件夹
///单位类型[KB,MB,GB]
///数字到四舍五入的数字
///



public enum UnitType { KB = 1, MB = 2, GB = 3 }
///
/// Find folder size
///
/// Target folder
/// Unit type [KB, MB, GB]
/// Number to digits to round up
///

public double FindFolderSize(DirectoryInfo d, UnitType u, int r)
{
    double divider = Math.Pow(1024, (int)u);
    double size = 0;
    foreach (FileInfo f in d.GetFiles())
        size += Convert.ToDouble(f.Length) / divider;
    foreach (DirectoryInfo c in d.GetDirectories())
        size += this.FindFolderSize(c, u, r);
    return Math.Round(size, r);
}


这篇关于在asp.net中查找文件夹大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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