Skip to content

Instantly share code, notes, and snippets.

@yamamaya
Created September 2, 2025 12:43
Show Gist options
  • Save yamamaya/7c8c1dcb57f67482c10e0dfed3b891a8 to your computer and use it in GitHub Desktop.
Save yamamaya/7c8c1dcb57f67482c10e0dfed3b891a8 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.
//***********************************************************************
namespace WindowsPathChecker {
internal class Program {
static void Main( string[] args ) {
// Get the value of the PATH environment variable
string path = Environment.GetEnvironmentVariable( "PATH" ) ?? "";
// Split the PATH value by semicolon and store in an array
string[] paths = path.Split( ';', StringSplitOptions.RemoveEmptyEntries );
// Use HashSet for duplicate checking
HashSet<string> uniquePaths = new HashSet<string>( StringComparer.OrdinalIgnoreCase );
// For each path
foreach ( string p in paths ) {
// Check if the path exists
bool exists = Directory.Exists( p );
// Check if the path is duplicated
bool isDuplicate = !uniquePaths.Add( p );
// Display the result
string result = "";
if ( !exists ) {
result += "X";
}
if ( isDuplicate ) {
result += "D";
}
Console.WriteLine( $"{result}\t{p}" );
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment