I'd like my program to scan the user's hard drive for java.exe.
I was considering using a for-loop and then going through each directory and then check if the directory names match the ones I would set up and then check in those for the java exe, but I'm sure there is a much more efficient way of doing so.
Any ideas on how to approach this?
Edit:
I've gone ahead and done some foreach loops, but it isn't going too well. I'm probably missing something:
// Scan for Java executable (java.exe)
foreach (String dir in Directory.GetDirectories("C:/"))
{
if (dir == "Program Files")
{
foreach (String _dir in Directory.GetDirectories(dir)) {
if (_dir == "Java")
{
foreach (String javaDir in Directory.GetDirectories(_dir))
{
if (javaDir == "jre7")
{
foreach (String binDir in Directory.GetDirectories(javaDir)) {
if (binDir == "bin")
{
foreach (String file in Directory.GetFiles(binDir))
{
if (file == "java.exe")
{
javaExe = file;
}
}
}
}
}
}
}
}
}
}