Is Recursion the Best Option for Determining the Max File Size in a Directory
<p>I wrote the following method to determine the max file size:</p>

<pre><code>    public static long GetMaxFileSize(string dirPath, long maxFileSize)
    {
        DirectoryInfo [] dirInfos = new DirectoryInfo(dirPath).GetDirectories();
        foreach (DirectoryInfo dirInfo in dirInfos)
        {
            DirectoryInfo [] subDirInfos = dirInfo.GetDirectories();
            foreach (DirectoryInfo subDirInfo in subDirInfos)
                maxFileSize = GetMaxFileSize(dirInfo.FullName, maxFileSize);

            FileInfo [] fileInfos = dirInfo.GetFiles();
            foreach (FileInfo fileInfo in fileInfos)
            {
                if (maxFileSize &lt; fileInfo.Length)
                    maxFileSize = fileInfo.Length;
            }
        }

        return maxFileSize;
    }
</code></pre>

<p><a href="http://rads.stackoverflow.com/amzn/click/0735619670" rel="nofollow">Code Complete</a> recommends to "use recursion selectively".  That being the case, I was wondering if the community thought this was a valid use of recursion.  If not, is there a better technique of doing this?</p>

<p><strong>EDIT:</strong> I can't use LINQ because its not available in .NET 2.0, but I don't want to tag this as a .NET 2.0 question only to further discussion points like Jared's below.  </p>

<p><strong>EDIT:</strong>  Cleaned up code based on an issue that was spotted in not getting the root directory's files.           </p>

<pre><code>   public static long GetMaxFileSize(DirectoryInfo dirInfo, long maxFileSize)
   {
       DirectoryInfo [] subDirInfos = dirInfo.GetDirectories();
       foreach (DirectoryInfo subDirInfo in subDirInfos)
       {
           maxFileSize = GetMaxFileSize(subDirInfo, maxFileSize);
       }

       FileInfo [] fileInfos = dirInfo.GetFiles();
       foreach (FileInfo fileInfo in fileInfos)
       {
           if (maxFileSize &lt; fileInfo.Length)
               maxFileSize = fileInfo.Length;
       }

       return maxFileSize;
   }
</code></pre>
