-
-
Save elderica/8715a436bf2cf2bf45b7b37bfbf89d9b to your computer and use it in GitHub Desktop.
WindowsPathChecker - A simple console application to check the validity of paths
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# *********************************************************************** | |
# 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