I am trying to list only latest excel files in my google bucket, my google bucket looks something like this:
bucket_name: *.xlsx file, *.xlsx file
Folder_1:
*.csv file , *.csv file
Folder 2: *.xlsx file, *.xlsx file, *.xlsx file
I want to only get the latest xlsx file that is in the bucket, not in any of the folders. I have the code to list all the blobs in the bucket (including everything in each folder) and order them depending on when they were last edited and then get the file name of the last edited file (which includes csv files in Folder 1), but I really only need the latest Excel file in the buck itself and can't seem to figure out how to do that.
bucket_name = 'bucket_name'
blobs = [(blob, blob.updated) for blob in client.list_blobs(bucket_name, prefix ='')]
latest = sorted(blobs, key=lambda tup: tup[1])[-1][0]
latest = latest.name.split('/')
file_name = ''.join(latest)
print(file_name)