How can I recursively count files and folders in Windows with C#?
===

I have a small program which iterates recursively through each file and folder under a target directory checking the names for specific characters.  It works just fine but I'm looking for help on how to make a specific method work faster.

I'm upgrading it to include a progress bar to indicate to my users how long they should expect to wait (some of the directories have over a hundred thousand items) and I'd like the progress bar to actually indicate how far through the list of items the program is, so therefore I need a number of items to set the `ProgressBar.Maximum` property to.

Here's the code I'm currently using:

    private void getMaxItems(string folderPath)
    {
        int numItems = 0;
        string[] items;

        try
        {
            items = Directory.GetFileSystemEntries(folderPath);
        }
        catch (UnauthorizedAccessException)
        {
            return;
        }
        numItems = items.Length;
        maxItems += items.Length;

        for (int x = 0; x < numItems; x++)
        {
            if (Directory.Exists(items[x].ToString()) == true && checkBox17.Checked == true)
                getMaxItems(items[x].ToString());
        }
    }

This is effectively the same exact code I'm using to check each item name with less functionality, meaning my users would have to wait twice as long just for an accurate progress bar.

There has to be a simpler way to recursively count how many files and folders there are inside a target directory.  What is it?