Python Forum

Full Version: How to fetch file from a list which match file extension
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi Team,

I am lerning python and trying some basic execution. I came across a situation where I want to restore data from AWS glacier with a specific filesystem type.
AS a n example : I am trying to restore only those files which are "xls" extension type.
=======================================================================================
import boto3

s3 = boto3.resource('s3')
bucket_name=input("please enter the bucket name you want to restore data from:")
prefix_date = input ("Please provide the archive date you want to restore data for:")
prefix_country = input ("Please provide the country code for data to be restored:")
file_type = input ("Please provide the file system type you want to restore , eg: xl ,txt, xml, etc..:")
bucket = s3.Bucket(bucket_name)
for obj in bucket.objects.filter(Prefix='20190101/US/'):
    print(obj.key)
=========================================================================================
output:
Output:
"C:\Program Files (x86)\Python37-32\python.exe" C:/Personal/Python_Training_Accenture/Python_scripts/test_glacier_restore.py please enter the bucket name you want to restore data from:suddhasil-bucket-test-1 Please provide the archive date you want to restore data for:20190101 Please provide the country code for data to be restored:US Please provide the file system type you want to restore , eg: xl ,txt, xml, etc..:xl 20190101/US/ 20190101/US/temp.xls.xlsx
=====================================================
the above code will print all ojects which are there under the bucket and prefix. How can I search specific file type as an exmaple above I want to just print "temp.xls.xlsx"

Any help is much appreciated on this please

Thanks
Suddhasil
How about making search on the path using regex.?