logo   

C#计算一个文件夹的大小 - 也想快乐的生活 - CSDN博客

private void Form1_Load(object sender, System.EventArgs e)
{
string A = FolderSize(@"C:\\").ToString();
this.label1.Text = A;
}
public static long FolderFileSize(string path)
{
long size = 0;
try
{
FileInfo [] files = (new DirectoryInfo(path)).GetFiles();
foreach(FileInfo file in files)
{
size += file.Length;
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
return size;
}


public static long FolderSize(string path)
{
long Fsize = 0;
try
{
Fsize = FolderFileSize(path);
DirectoryInfo [] folders = (new DirectoryInfo(path)).GetDirectories();
foreach(DirectoryInfo folder in folders)
{

Fsize += FolderSize(folder.FullName);

}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
return Fsize;
}
Tags:
访问文章出处: http://blog.csdn.net/xiaoxiaohai123/archive/2007/05/18/1615097.aspx(C#计算一个文件夹的大小 - 也想快乐的生活 - CSDN博客)

上一篇: 添加svn服务 到window 服务 - Open source of memory - JavaEye技术网站
下一篇: C#如何控制系统服务的重启!? .NET技术 / C# - CSDN社区 community.csdn.net