목적
- 바로 아래 depth의 디렉터리의 목록을 뽑아낸다.
- 예를들어 아래와 같은 구조가 있다고 할 때에, /a/b2를 파라미터로 넣으면 [a/b2/c1, a/b2/c2]의 결과를 얻고싶다.
s3://bucket/a/b1/c1/d1
s3://bucket/a/b1/c1/d2
s3://bucket/a/b1/c2/d1
s3://bucket/a/b1/c3/d1
s3://bucket/a/b1/c4/d1
s3://bucket/a/b2/c1/d1
s3://bucket/a/b2/c2/d2
s3://bucket/a/b3/c2/d1
s3://bucket/a/b4/c3/d1
s3://bucket/a/b5/c1/d1
과정
from boto3 import client
...
s3_client = client('s3')
bucket_name = "bucket"
prefix = "a/b2/"
dir_info = s3_client.list_objects(Bucket=bucket_name, Prefix=prefix, Delimiter='/')['CommonPrefixes']
=> [{'Prefix': 'a/b2/c1/'}, {'Prefix': 'a/b2/c2/'}]
- 위와 같이 Delimiter 옵션을 추가 시 바로 하위 depth 까지만 검색이 된다.
반응형
'AWS' 카테고리의 다른 글
[AWS] python으로 s3에 있는 parquet 파일 읽기 (0) | 2022.02.03 |
---|---|
[AWS] Python으로 S3 Object(디렉터리 혹은 파일)의 용량 확인 (0) | 2021.07.08 |
댓글