Search code examples
c#.netdirectory-structureenumerate

enumerating apache directory versions using .net


I am trying to enumerate the file system, checking for apache versions installed in wamp. The apache folder usually has the version numbers in the name.

My goal is first to look for this folder in each drive

2.2.19
2.2.18
2.2.1
2.2.0

so the file path can look like c:\wamp\bin\apache\apache2.2.20 or c:\wamp\bin\apache\apache2.2.1

How do I check if this folder exists and also get the version from the folder name?


Solution

  • You can use Directory.GetDirectories() to get all directories.

    Something like this should work for you:

    var directory = @"C:\wamp\bin\apache\";
    foreach(var dir in Directory.GetDirectories(directory)) {
        var version = dir.Replace(directory, "")
                         .Replace("Apache", "");
    
        Console.WriteLine("{0} is installed", version);
    }