I am looking for a good way to find all folders that have contents that are say 500k or less. I think this involves recursively going to the lowest folder in a hierarchy and then "reading up" to get a size total. All ideas appreciated (something int he .NET framework or PowerShell if I really have to), thanks.
Asked
Active
Viewed 227 times
1 Answers
1
This could help you out.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace GetDirectorySize
{
class Program
{
static void Main(string[] args)
{
long maxFolderSizeInBytes = 20000000;
foreach (var directory in Directory.GetDirectories(@"C:\Projects\Visual Studio 2010\"))
{
string[] a = Directory.GetFiles(directory, "*.*");
long i = 0;
foreach (string name in a)
{
FileInfo info = new FileInfo(name);
i += info.Length;
}
if (i <= maxFolderSizeInBytes)
{
Console.WriteLine(directory);
}
}
Console.ReadLine();
}
}
}

Michael D. Irizarry
- 6,186
- 5
- 30
- 35