0

I am using cloudpathlib to download bulk files from AWS s3. My question is how can I download only csv files using this package?

from cloudpathlib import CloudPath

root_dir = CloudPath('s3://dir1/dir2/*.csv')
root_dir.download_to(to_path) 

In s3://dir1/dir2/ , there are csv and pdf files. Note that I am not in a position to use boto3 and I generally wouldn’t prefer loops.

Thanks.

pnna
  • 113
  • 1
  • 6

1 Answers1

1

Try this:

root_dir = CloudPath('s3://dir1/')
for f in root_dir.glob('dir2/*.csv'):
    filename = f.name.replace('/', '_') 
    f.download_to_filename(filename)

This assumes that your bucket is named dir1 and that the files are in dir2/ folder.

kgiannakakis
  • 103,016
  • 27
  • 158
  • 194