python-3.xminio

How to list_objects in aiobotocore not recursively


I have the following code for getting a list of objects.

paginator = self.client.get_paginator('list_objects')
async for result in paginator.paginate(Bucket=bucket_name, Prefix=prefix):
      for file in result.get('Contents', []):
          yield file

What do I need to add to display objects in only one directory, without recursion?


Solution

  • Add Delimiter='/' kwarg

    paginator = self.client.get_paginator('list_objects')
    async for result in paginator.paginate(
        Bucket=bucket_name, 
        Prefix=prefix, 
        Delimiter='/',
    ):
        for file in result.get('Contents', []):
             yield file