[转载]获取文件夹的大小 递归
public long GetDirectoryLength(string dirPath){
if(!Directory.Exists(dirPath))return 0;
long len=0;
DirectoryInfo di=new DirectoryInfo(dirPath);
foreach(FileInfo fi in di.GetFiles()){
len+=fi.Length;
}
DirectoryInfo[] dis=di.GetDirectories();
if(dis.Length>0){
for(int i=0;i<dis.Length;i++){
len+=GetDirectoryLength(dis[i].FullName);
}
}
return len;
}
if(!Directory.Exists(dirPath))return 0;
long len=0;
DirectoryInfo di=new DirectoryInfo(dirPath);
foreach(FileInfo fi in di.GetFiles()){
len+=fi.Length;
}
DirectoryInfo[] dis=di.GetDirectories();
if(dis.Length>0){
for(int i=0;i<dis.Length;i++){
len+=GetDirectoryLength(dis[i].FullName);
}
}
return len;
}