[Python] How can I get the list of only folders in amazon S3 using python boto?

Discussão em 'Python' iniciado por Stack, Fevereiro 16, 2025.

  1. Stack

    Stack Membro Participativo

    I am using boto and python and amazon s3.

    If I use

    [key.name for key in list(self.bucket.list())]

    then I get all the keys of all the files.

    mybucket/files/pdf/abc.pdf
    mybucket/files/pdf/abc2.pdf
    mybucket/files/pdf/abc3.pdf
    mybucket/files/pdf/abc4.pdf
    mybucket/files/pdf/new/
    mybucket/files/pdf/new/abc.pdf
    mybucket/files/pdf/2011/


    what is the best way to

    1. either get all folders from s3
    2. or from that list just remove the file from the last and get the unique keys of folders


    I am thinking of doing like this

    set([re.sub("/[^/]*$","/",path) for path in mylist]

    Continue reading...

Compartilhe esta Página