🟣 C# / .NET 6+

Get The Windows Internet cache (INetCache) Size Report (C#)

Recursively sums the size of the Windows Internet cache (INetCache), read-only (no deletion).

By WindowsScripting.com · 1 KB
BrowserCacheSizeReport.cs
// BrowserCacheSizeReport.cs
//
// Reports how much disk space the Windows Internet cache (INetCache) is using, read-only.
//
// Usage: dotnet new console -o BrowserCacheSizeReport, replace Program.cs
// with this file, then dotnet run.

using System;
using System.IO;
using System.Linq;

string targetPath = Environment.ExpandEnvironmentVariables(@"%LOCALAPPDATA%\Microsoft\Windows\INetCache");

if (!Directory.Exists(targetPath))
{
    Console.WriteLine($"{targetPath} does not exist on this machine.");
    return;
}

// IgnoreInaccessible (the EnumerationOptions default) skips subfolders we
// can't read instead of throwing — GetFiles(pattern, SearchOption) does not.
var enumOptions = new EnumerationOptions { RecurseSubdirectories = true, IgnoreInaccessible = true };
var files = new DirectoryInfo(targetPath).GetFiles("*", enumOptions);
long totalBytes = files.Sum(f => f.Length);

Console.WriteLine(targetPath);
Console.WriteLine($"  Files: {files.Length}");
Console.WriteLine($"  Total size: {(totalBytes / 1024.0 / 1024.0):F2} MB");