得到目录大小

类别:.NET开发 点击:0 评论:0 推荐:

public static long DirSize(DirectoryInfo d)
    {   
        long Size = 0;   
        // Add file sizes.
        FileInfo[] fis = d.GetFiles();
        foreach (FileInfo fi in fis)
        {     
            Size += fi.Length;   
        }
        // Add subdirectory sizes.
        DirectoryInfo[] dis = d.GetDirectories();
        foreach (DirectoryInfo di in dis)
        {
            Size += DirSize(di);  
        }
        return(Size); 
    }

 

本文地址:http://com.8s8s.com/it/it43297.htm