title: Searching a directory for folders and files using python
body: <p>I have a directory structure like the one given below.</p>
  
  <pre><code>         MainFolder 
               |
             [lib] 
           /   |   \
         [A]  [B]  [C] -- file1.so 
          |     |         file2.so
     file1.so   file1.so
     file2.so   file2.so    
  </code></pre>
  
  <p>I'm trying to look for the 'lib' folder in that structure which might not be there at times. So I'm using the following to check for the presence of the 'lib' folder:</p>
  
  <pre><code>   if os.path.isdir(apkLocation + apkFolder + '/lib/'):
  </code></pre>
  
  <p>If lib folder exists, then I carry on to search the folders  inside 'lib'. I have to store the names of the folder A,B and C and look for the files ending with '.so' whose path should be stored as /lib/A/file1.so,/lib/A/file2.so and so on.</p>
  
  <pre><code> if os.path.isdir(apkLocation + apkFolder + '/lib/'):
     for root, dirs, files in os.walk(apkLocation + apkFolder):
              for name in files:
                  if name.endswith(("lib", ".so")):
                      print os.path.abspath(name) 
  </code></pre>
  
  <p>This gives me an out </p>
  
  <pre><code>                  file1.so
                    file2.so
                    file1.so
                    file2.so
                    file1.so
                    file2.so
  </code></pre>
  
  <p>Desired output:</p>
  
  <pre><code>           /lib/A/file1.so
             /lib/A/file2.so
             /lib/B/file1.so
             /lib/B/file2.so
             /lib/C/file1.so
             /lib/C/file2.so
  </code></pre>
  
  <p>and also the folders A,B and C are to be saved separately.</p>