If you play a little with her, trying to calculate her, and itโs amazing - she accelerated here in my car (up to three times on an ATV), I donโt know if she really is in all cases, but give her a try ...
.NET4.0 code (or use 3.5 with TaskParallelLibrary)
private static long DirSize(string sourceDir, bool recurse) { long size = 0; string[] fileEntries = Directory.GetFiles(sourceDir); foreach (string fileName in fileEntries) { Interlocked.Add(ref size, (new FileInfo(fileName)).Length); } if (recurse) { string[] subdirEntries = Directory.GetDirectories(sourceDir); Parallel.For<long>(0, subdirEntries.Length, () => 0, (i, loop, subtotal) => { if ((File.GetAttributes(subdirEntries[i]) & FileAttributes.ReparsePoint) != FileAttributes.ReparsePoint) { subtotal += DirSize(subdirEntries[i], true); return subtotal; } return 0; }, (x) => Interlocked.Add(ref size, x) ); } return size; }
spookycoder Jun 05 '10 at 17:02 2010-06-05 17:02
source share