Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] A function similar to s3 ls #16

Open
aamster opened this issue Oct 14, 2024 · 0 comments
Open

[FEATURE] A function similar to s3 ls #16

aamster opened this issue Oct 14, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@aamster
Copy link

aamster commented Oct 14, 2024

Summary

I needed a function that is similar to ls to just list paths at a given S3URI.

Justification

list_s3_paths is recursive and only lists files, not directories, for example, as ls would.

Solution

I implemented this function for aibs-informatics-AD-image-convert library:

def list_directories(s3_path: S3URI, **kwargs):
    s3_client = get_s3_client(**kwargs)
    paginator = s3_client.get_paginator("list_objects_v2")

    operation_parameters = {
        "Bucket": s3_path.bucket,
        "Delimiter": "/",
        "Prefix": s3_path.key,
    }

    page_iterator = paginator.paginate(**operation_parameters)

    directories = []

    for page in page_iterator:
        if "CommonPrefixes" in page:
            for common_prefix in page["CommonPrefixes"]:
                directories.append(common_prefix["Prefix"])

    return directories

If this is implemented, that function should be replaced with this new one.

@aamster aamster added the enhancement New feature or request label Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant