Created
September 2, 2025 12:43
-
-
Save yamamaya/7c8c1dcb57f67482c10e0dfed3b891a8 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. | |
//*********************************************************************** | |
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