如何获得文件夹大小 以前用ASP时,好象是FOLDER的,到了.NET查了一下,在Directory中没有SIZE或者LENGTH属性.难道要自己编程,遍历所有文件夹中的文件和子文件夹,然后计算大小?有米有更好的方法啊? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public static long getDirSize(string path) { System.IO.DirectoryInfo dir=new System.IO.DirectoryInfo(path); long count=0; foreach(System.IO.FileSystemInfo fi in dir.GetFileSystemInfos()) { if(fi.Attributes.ToString().ToLower().Equals("directory")) { count+=getDirSize(fi.FullName); } else { System.IO.FileInfo finf=new System.IO.FileInfo(fi.FullName); count+=finf.Length; } } return count; } 好象是fi.Attributes.Directory吧,没想到你连代码也给我了,其实我就问一下有没有现成的,因为类库不是很熟。不过还是谢谢了 json 反序列化 为.net对象 ASP.NET做个人网站流程 求教类似论坛读贴功能 一次输入几行数据,有一行不输入,数据库中就有一条空的数据 gridView数据刷新 页面无刷新 菜鸟提问:跟着教程做完DAL(数据集)和BLL后,回到前台做WEB的登录时,如何访问BLL中的方法呢? 今天辞职,散分.并问一个.net 2005的问题 帮忙看看jQuery验证用户名是否存在的问题 Access的参数查询问题? Crystal Report 的问题,100分 url中可以传中文吗? 各位兄弟们,请帮小弟一把!!!
{
System.IO.DirectoryInfo dir=new System.IO.DirectoryInfo(path);
long count=0;
foreach(System.IO.FileSystemInfo fi in dir.GetFileSystemInfos())
{
if(fi.Attributes.ToString().ToLower().Equals("directory"))
{
count+=getDirSize(fi.FullName);
}
else
{
System.IO.FileInfo finf=new System.IO.FileInfo(fi.FullName);
count+=finf.Length;
}
}
return count;
}
不过还是谢谢了