Python Forum
How to fetch file from a list which match file extension
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to fetch file from a list which match file extension
#1
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
Reply
#2
How about making search on the path using regex.?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to write variable in a python file then import it in another python file? tatahuft 4 876 Jan-01-2025, 12:18 AM
Last Post: Skaperen
  Get an FFMpeg pass to subprocess.PIPE to treat list as text file? haihal 2 991 Nov-21-2024, 11:48 PM
Last Post: haihal
  How to re-register .py file extension to new moved Python dir (on Windows)? pstein 5 1,248 Nov-06-2024, 03:06 PM
Last Post: DeaD_EyE
  JSON File - extract only the data in a nested array for CSV file shwfgd 2 1,033 Aug-26-2024, 10:14 PM
Last Post: shwfgd
  FileNotFoundError: [Errno 2] No such file or directory although the file exists Arnibandyo 0 834 Aug-12-2024, 09:11 AM
Last Post: Arnibandyo
  To fetch and iterate data from CSV file using python vyom1109 3 972 Aug-05-2024, 10:05 AM
Last Post: Pedroski55
  writing list to csv file problem jacksfrustration 5 2,199 Jul-04-2024, 08:15 PM
Last Post: deanhystad
  "[Errno 2] No such file or directory" (.py file) IbrahimBennani 13 6,176 Jun-17-2024, 12:26 AM
Last Post: AdamHensley
  file open "file not found error" shanoger 8 6,171 Dec-14-2023, 08:03 AM
Last Post: shanoger
  Search Excel File with a list of values huzzug 4 2,733 Nov-03-2023, 05:35 PM
Last Post: huzzug

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020