Skip to content

Instantly share code, notes, and snippets.

@elderica
Forked from yamamaya/WindowsPathChecker.cs
Last active September 3, 2025 11:29
Show Gist options
  • Save elderica/8715a436bf2cf2bf45b7b37bfbf89d9b to your computer and use it in GitHub Desktop.
Save elderica/8715a436bf2cf2bf45b7b37bfbf89d9b to your computer and use it in GitHub Desktop.
WindowsPathChecker - A simple console application to check the validity of paths
# ***********************************************************************
# WindowsPathChecker
# A simple console application to check
# the validity of paths in the Windows PATH environment variable.
# ***********************************************************************
using namespace System
using namespace System.IO
using namespace System.Collections.Generic
Set-StrictMode -Verbose -Version Latest
$paths = $env:Path.Split(';', [StringSplitOptions]::RemoveEmptyEntries)
$uniquePaths = [HashSet[string]]::new([StringComparer]::OrdinalIgnoreCase)
foreach($p in $paths) {
$exists = [Directory]::Exists($p)
$isDuplicate = (-not ($uniquePaths.Add($p)))
$result = ""
if (-not $exists) {
$result += "X"
}
if ($isDuplicate) {
$result += "D"
}
[Console]::WriteLine("${result} ${p}")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment