title: List all directories and subdirectories path from s3
body: <p>I know there are allot of similar questions (especially <a href="https://stackoverflow.com/questions/17375127/how-can-i-get-list-of-only-folders-in-amazon-s3-using-python-boto">this</a>) asked on SO, but none of the answer actually solves my situation. And ofcourse I know there is no such thing as a folder in S3. Internally everything is stored as a key. </p>
  
  <p>I have a following directory structure;</p>
  
  <pre><code>TWEAKS/date=2020-03-19/hour=20/file.gzip
  TWEAKS/date=2020-03-20/hour=21/file.gzip
  TWEAKS/date=2020-03-21/hour=22/file.gzip
  TWEAKS/date=2020-03-22/hour=23/file.gzip
  </code></pre>
  
  <p>I tried this;</p>
  
  <pre><code>def list_folders(s3_client, bucket_name):
      response = s3_client.list_objects_v2(Bucket=bucket_name, Prefix='TWEAKS/', Delimiter='/')
      for content in response.get('CommonPrefixes', []):
          yield content.get('Prefix')
  
  s3_client = session.client('s3')
  folder_list = list_folders(s3_client, bucket_name)
  for folder in folder_list:
      print('Folder found: %s' % folder)
  </code></pre>
  
  <p>But this only list all directories upto the first level</p>
  
  <pre><code>Folder found: TWEAKS/date=2020-03-19/
  Folder found: TWEAKS/date=2020-03-20/
  Folder found: TWEAKS/date=2020-03-21/
  Folder found: TWEAKS/date=2020-03-22/
  </code></pre>
  
  <p>Now I cannot add the subdirectory into the Prefix because the names are not same <code>hour=21</code>, <code>hour=22</code> ... Is there a way to achieve this output ?</p>
  
  <pre><code>Folder found: TWEAKS/date=2020-03-19/hour=20/
  Folder found: TWEAKS/date=2020-03-20/hour=21/
  Folder found: TWEAKS/date=2020-03-21/hour=22/
  Folder found: TWEAKS/date=2020-03-22/hour=23/
  </code></pre>