Skip to content

Pm9-Technology/FolderSizeScanner

Repository files navigation

Perimeter 9 — Folder Size Scanner

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.

Features

  • 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

Screenshots

Perimeter 9 Logo

Architecture

Project Structure

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

Key Classes

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

Data Flow

  1. User selects a folder path and scan depth, then clicks Scan
  2. ScanFolder() runs on a background Task with a CancellationToken
  3. File system enumeration uses Win32 P/Invoke (FindFirstFileW/FindNextFileW) for performance
  4. A FolderInfo tree 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)
  5. A UI timer (200ms) polls scan progress and refreshes the tree view in real-time
  6. On completion, the tree is sorted by size (descending) and the final state is rendered

Threading & Concurrency

  • Parallelization: Parallel.ForEach at depths 0–1 only (deeper levels are sequential to reduce overhead)
  • Max parallelism: Environment.ProcessorCount
  • Thread safety: Interlocked operations on size/count accumulators; lock() on FolderInfo.Children in parallel sections
  • UI marshaling: BeginInvoke to update controls from background threads

UI Layout

The form uses a three-panel dock layout:

  1. Toolbar (top, 56px) — Logo, title, path input, depth selector, Browse/Scan/Export buttons
  2. Tree card (fill)ModernTreeView with rounded card border and context menu
  3. Footer (bottom, 40px)ModernProgressBar and status label

Theme

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

Export Formats

TXT (indented outline)

Documents  --  5.2 GB  (1,234 files)
  Photos  --  3.1 GB  (890 files)
  Videos  --  2.0 GB  (45 files)

CSV

Path,Size (Bytes),Size,Files,Folders
C:\Documents,5580390400,5.2 GB,1234,12
C:\Documents\Photos,3328599654,3.1 GB,890,5

Build & Run

Prerequisites

Build

dotnet build

Run

dotnet run

Publish (self-contained single file)

dotnet publish -c Release -r win-x64 --self-contained -p:PublishSingleFile=true

Technical Notes

  • 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

About

A modern Windows desktop app for analyzing disk usage with an interactive tree view, color-coded size indicators, and high-performance Win32 scanning. Built with .NET 9 WinForms.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages