You asked for code? Here is it: (just copy to a console project and replace Program.cs with the following code)
(Keep in mind that file sizes on drives are not meassured like 1kB = 1000B but 1kB = 1024B, ...)
Counting can take some time on big drives with a lot of files!
using System;
using System.IO;
namespace CountFiles
{
class Program
{
static void Main(string[] args)
{
string strRootPath = @"D:\";
int iCount10kB = 0,iCount1000kB = 0,iCount100000kB = 0, iCountBigger = 0;
CountFiles(strRootPath,
ref iCount10kB, ref iCount1000kB, ref iCount100000kB, ref iCountBigger);
Console.WriteLine("Results for root directory {0}", strRootPath);
Console.WriteLine("Files 0kB - 10 kB: {0}", iCount10kB);
Console.WriteLine("Files 10kB - 1000 kB: {0}", iCount1000kB);
Console.WriteLine("Files 1000kB - 100000 kB: {0}", iCount100000kB);
Console.WriteLine("Files bigger than 100000 kB: {0}", iCountBigger);
Console.ReadKey();
}
static void CountFiles(string strRootPath,
ref int iCount10kB, ref int iCount1000kB, ref int iCount100000kB, ref int iCountBigger)
{
try
{
string[] astrFiles = Directory.GetFiles(strRootPath);
foreach (string strFile in astrFiles)
{
long iFileLength = new FileInfo(strFile).Length;
if (iFileLength < 10000)
iCount10kB++;
else if (iFileLength < 1000000)
iCount1000kB++;
else if (iFileLength < 100000000)
iCount100000kB++;
else
iCountBigger++;
}
}
catch
{
}
try
{
string[] astrSubDirs = Directory.GetDirectories(strRootPath);
foreach (string strSubDir in astrSubDirs)
{
CountFiles(strSubDir,
ref iCount10kB, ref iCount1000kB, ref iCount100000kB, ref iCountBigger);
}
}
catch
{
}
}
}
}