Enumerate directories to a given search depth Since I had been in the need of finding directories from a startpath with different search depth levels, I created this little helper class.

This class is using objects of the System.IO namespace.

public class IOHelper
{
    public const int AllDirectories = -1;
    public const int TopDirectoryOnly = 0;
    private const char WildCard = '*';

    public static IEnumerable&lt;String&gt; EnumerateDirectories(String startDirectory,  int depth)
    {
        return EnumerateDirectories(startDirectory, "*.*", depth);
    }

    public static IEnumerable&lt;String&gt; EnumerateDirectories(String startDirectory, String searchPattern, int depth)
    {
        if (depth &lt; AllDirectories) { throw new ArgumentOutOfRangeException("depth", "Depth needs to be -1(AllDirectories) or greater"); }

        switch (depth)
        {
            case AllDirectories:
                return Directory.EnumerateDirectories(startDirectory, searchPattern, SearchOption.AllDirectories);

            case TopDirectoryOnly:
                return Directory.EnumerateDirectories(startDirectory, searchPattern, SearchOption.TopDirectoryOnly);

            default:
                return EnumerateDirectoriesInDepth(startDirectory, searchPattern, depth);
        }
    }

    private static IEnumerable&lt;String&gt; EnumerateDirectoriesInDepth(String startDirectory, String searchPattern, int depth)
    {
        IEnumerable&lt;String&gt; directories = EnumerateDirectoriesInDepth(startDirectory, depth);

        Boolean isWildCardSearch = searchPattern.Contains(WildCard);

        if (!isWildCardSearch)
        {
            searchPattern = String.Concat("\\", searchPattern);
            return directories.Where(d =&gt; d.EndsWith(searchPattern));
        }

        IEnumerable&lt;String&gt; enumeratedDirectories = Enumerable.Empty&lt;String&gt;();
        foreach (String directory in directories)
        {
            enumeratedDirectories = enumeratedDirectories.Concat(Directory.EnumerateDirectories(directory, searchPattern));
        }

        return enumeratedDirectories;
    }

    private static IEnumerable&lt;String&gt; EnumerateDirectoriesInDepth(String startDirectory, int depth)
    {
        if (depth &lt;= TopDirectoryOnly) { return Enumerable.Empty&lt;String&gt;(); }

        IEnumerable&lt;String&gt; directories = Directory.EnumerateDirectories(startDirectory, "*.*", SearchOption.TopDirectoryOnly);

        if (!directories.Any()) { return directories; }

        depth = depth - 1;

        IEnumerable&lt;String&gt; subDirectories = Enumerable.Empty&lt;String&gt;();
        foreach (String directory in directories)
        {
            subDirectories = subDirectories.Concat(EnumerateDirectoriesInDepth(directory, depth));
        }

        return directories.Concat(subDirectories);
    }
}  


I would like to get a review on all aspects.
Since the class has only static and constant members, you should make the entire class static.  It eliminates the unnecessary empty instance constructor the framework automatically generates.  (see code analysis rules CA1052 and CA1053).

You should also generally use the type aliases provided (i.e., string instead of String, bool instead of Boolean, etc. - see StyleCop rule SA1121).

Additionally, I would change the recursion in EnumerateDirectoriesInDepth so it does not have to recurse another step when the depth is zero.

private static IEnumerable&lt;string&gt; EnumerateDirectoriesInDepth(string startDirectory, int depth)
{
    var directories = Directory.EnumerateDirectories(startDirectory, "*.*", SearchOption.TopDirectoryOnly);

    if (depth == TopDirectoryOnly || !directories.Any())
    {
        return directories;
    }