title: Recursive problems in Python using os.walk()
body: <p>I'm very new to using Python (strong c# background), so I'm still learning what results I should expect from functions. I'm getting weird results creating a recursive function which will borrow down a directory structure.
  I'm using the os.walk() function and it appears to me that once you borrow deep enough, the return results for the 'directories' aren't been cleared when finding an empty folder.
  I"m using Eclipse as my IDE and Python 2.7</p>
  
  <pre><code>def CheckSubFolder( folder ):
  
      print "Checking folders in : " + folder;
  
      for (root, directories, files) in os.walk(folder):
          for folder2 in directories:
              print folder2;
  
          for folder2 in directories:
              CheckSubFolder( folder + "\\" + folder2);
  
      return;
  
  # Code Entry
  InFolder = sys.argv[1];
  CheckSubFolder( InFolder );
  sys.exit(); 
  </code></pre>
  
  <p>Here is the example directory structure that I'm using.</p>
  
  <pre><code>State
      -&gt; 1
          -&gt; 2
          -&gt; 3
              -&gt; 4
              -&gt; 5
                  -&gt; 6
                  -&gt; 7
  </code></pre>
  
  <p>Here are the results that I'm being return:</p>
  
  <pre><code>Checking folders in : \\State
  1
  Checking folders in : \\State\1
  2
  3
  Checking folders in : \\State\1\2
  Checking folders in : \\State\1\3
  4
  5
  Checking folders in : \\State\1\3\4
  Checking folders in : \\State\1\3\5
  6
  7
  Checking folders in : \\State\1\3\5\6
  Checking folders in : \\State\1\3\5\7
  6
  7
  Checking folders in : \\State\1\3\6
  Checking folders in : \\State\1\3\7
  4
  5
  Checking folders in : \\State\1\4
  Checking folders in : \\State\1\5
  6
  7
  Checking folders in : \\State\1\6
  Checking folders in : \\State\1\7
  </code></pre>