C# 直接获取文件夹占用空间大小
/// <summary> /// /// </summary> /// <param name="path"></param> /// <returns></returns> public static double GetDirectorySize(string path) { double result = 0d; try { if (Directory.Exists(path)) { dynamic fso = Activator.CreateInstance(Type.GetTypeFromProgID("Scripting.FileSystemObject")); dynamic fldr = fso.GetFolder(path); result = (double)fldr.size; result = result / 1024 / 1024 / 1024; } else { result = 0d; } } catch (Exception ex) { result = 0d; } return result; }