A modern Windows desktop application that analyzes folder structures and displays disk usage distribution in an interactive tree view. Quickly identify which folders and subfolders consume the most disk space.
- Recursive folder scanning with configurable depth (1–50 levels)
- Real-time progress tracking with animated progress bar during scans
- Interactive tree view with visual size bars and color-coded indicators
- Color-coded sizing — red (>=50%), orange (>=25%), amber (>=10%), blue (<10%)
- Export to TXT (indented outline) or CSV (with raw bytes)
- Sub-scan — right-click any folder node to re-scan from that point
- Double-click a folder to open it in Windows Explorer
- Junction/reparse point detection — skipped to prevent infinite loops
- Responsive cancellation — cancel a scan at any time
- Keyboard shortcut — press Enter to start a scan
FolderSizeScanner/
├── Program.cs # Entry point (STAThread, WinForms bootstrap)
├── Form1.cs # Main form — scan logic, UI orchestration, export
├── Form1.Designer.cs # WinForms designer layout and control initialization
├── ModernControls.cs # Custom owner-drawn controls (button, progress bar, tree view)
├── ModernTheme.cs # Static theme constants (colors, fonts, dimensions)
├── FolderSizeScanner.csproj # Project config — .NET 9.0 Windows, no NuGet deps
├── FolderHome.ico # Application icon
└── P9.png # Logo image
| Class | File | Purpose |
|---|---|---|
Form1 |
Form1.cs | Main application controller — scan management, UI updates, export |
FolderInfo |
Form1.cs | Data model representing a folder with size, children, file/folder counts |
ModernButton |
ModernControls.cs | Flat, rounded WinUI3-style button (primary/secondary variants) |
ModernProgressBar |
ModernControls.cs | Pill-shaped progress bar with shimmer animation and marquee mode |
ModernTreeView |
ModernControls.cs | Owner-drawn tree view with size bars, chevrons, hover effects |
ModernTheme |
ModernTheme.cs | Static color palette, fonts, dimensions, and helper methods |
- User selects a folder path and scan depth, then clicks Scan
ScanFolder()runs on a backgroundTaskwith aCancellationToken- File system enumeration uses Win32 P/Invoke (
FindFirstFileW/FindNextFileW) for performance - A
FolderInfotree is built recursively:- Depths 0–maxDepth: Full tree nodes with names and hierarchy
- Beyond maxDepth:
TallyFolder()sums sizes without building tree nodes (up to a hard limit of 200 levels)
- A UI timer (200ms) polls scan progress and refreshes the tree view in real-time
- On completion, the tree is sorted by size (descending) and the final state is rendered
- Parallelization:
Parallel.ForEachat depths 0–1 only (deeper levels are sequential to reduce overhead) - Max parallelism:
Environment.ProcessorCount - Thread safety:
Interlockedoperations on size/count accumulators;lock()onFolderInfo.Childrenin parallel sections - UI marshaling:
BeginInvoketo update controls from background threads
The form uses a three-panel dock layout:
- Toolbar (top, 56px) — Logo, title, path input, depth selector, Browse/Scan/Export buttons
- Tree card (fill) —
ModernTreeViewwith rounded card border and context menu - Footer (bottom, 40px) —
ModernProgressBarand status label
All visual constants are defined in ModernTheme.cs:
- Form background: #F3F3F3 (light gray)
- Card background: #FFFFFF (white)
- Accent: #005FB8 (blue)
- Font: Segoe UI, 8.5–10pt
- Rounding: 6px cards, 4px buttons
Documents -- 5.2 GB (1,234 files)
Photos -- 3.1 GB (890 files)
Videos -- 2.0 GB (45 files)
Path,Size (Bytes),Size,Files,Folders
C:\Documents,5580390400,5.2 GB,1234,12
C:\Documents\Photos,3328599654,3.1 GB,890,5- .NET 9.0 SDK (Windows)
dotnet builddotnet rundotnet publish -c Release -r win-x64 --self-contained -p:PublishSingleFile=true- No NuGet dependencies — uses only .NET framework libraries (System.Windows.Forms, System.Drawing, System.Runtime.InteropServices)
- Win32 P/Invoke for file enumeration — significantly faster than managed
DirectoryInfo - Reparse point detection prevents scanning junctions and symbolic links that could cause infinite recursion
- Hard recursion limit of 200 levels prevents stack overflow on deeply nested structures
- Sub-scan propagates size deltas up the ancestor chain to keep totals accurate
