Simple C# function to find an executable being run in the path

original post @

public string FindInPath(string filenameToFind)


string Path = System.Environment.GetEnvironmentVariable("PATH");

string[] folders = Path.Split(new char[] {';'});

foreach (string folder in folders)


DirectoryInfo dirInfo = new DirectoryInfo(folder);

if (dirInfo != null)


FileInfo[] files = dirInfo.GetFiles();

foreach (FileInfo file in files)

if (file.Name.ToLower().Contains(filenameToFind))

    return dirInfo.ToString();



return string.Empty;


No comments:

Post a Comment