title: Exclude files in a dictionary
body: <p>I have a script, which recollects in a dictionary the directories, the number of sub-directories and files in it. I need to exclude the files of this dictionary but I am not able to do that.</p>
  
  <pre><code>path="/home/tmp"
  
  def PathToDict(path):
      st = os.lstat(path)
      result = {}
      if S_ISDIR(st.st_mode):
          result['Path'] = path
          result['Subdir'] = {
             name: PathToDict(os.path.join(path,name))                       
             for name in os.listdir(path)}
          result['Num_Subdir'] = int(len([i for i, j, k in os.walk(path)]))
  </code></pre>
  
  <p>This is the function which recollects all folders, but the problem is that also recollect files like .sh or logs. I'm trying to use os.path.isdir method but I can't.</p>
  
  <p>Actual output: </p>
  
  <pre><code>'Path': '/var/lib/jenkins/jobs/updates',
              'Num_Subdir': 8,
              'Subdir': {
                  'nextBuildNumber': {},
                  'config.xml': {},
                  'lastSuccessful': {},
                  'lastStable': {},
                  'builds': {
                      'Path': '/var/lib/jenkins/jobs/updates2',
                      'Num_Subdir': 7,
                      'Subdir': {
                          'lastStableBuild': {},
                          'lastSuccessfulBuild': {},
                          '1': {
                              'Path': '/var/lib/jenkins/jobs/updates3',
                              'Num_Subdir': 1,
                              'Subdir': {
                                  'changelog.xml': {},
                                  'injectedEnvVars.txt': {},
                                  'build.xml': {},
                                  'changelog.xml.temp2': {},
                                  'log': {}
  </code></pre>
  
  <p>And i need the output excluding .xml and .txt for example. In the root of the path, i also have files and they are listed in dictionary and i need to exclude those files too.</p>