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
  file open "file not found error" shanoger 8 1,089 Dec-14-2023, 08:03 AM
Last Post: shanoger
  Search Excel File with a list of values huzzug 4 1,228 Nov-03-2023, 05:35 PM
Last Post: huzzug
  Need to replace a string with a file (HTML file) tester_V 1 762 Aug-30-2023, 03:42 AM
Last Post: Larz60+
  How can I change the uuid name of a file to his original file? MaddoxMB 2 921 Jul-17-2023, 10:15 PM
Last Post: Pedroski55
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 1,092 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
Question How to append integers from file to list? Milan 8 1,447 Mar-11-2023, 10:59 PM
Last Post: DeaD_EyE
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 1,114 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  Find (each) element from a list in a file tester_V 3 1,205 Nov-15-2022, 08:40 PM
Last Post: tester_V
Photo Making Zip file of a file and Directory Nasir 2 1,019 Oct-07-2022, 02:01 PM
Last Post: Nasir
  Need Help: Convert .pcl file to .pdf file ManuRaval 6 2,541 Sep-13-2022, 01:31 PM
Last Post: ManuRaval

Forum Jump:

User Panel Messages

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