Используя os.path.getsize
:
for root,dirs,files in os.walk('/mnt/usbdrive/data'):
for file in files:
if os.path.getsize(file) >= 1020.0:
s3C.upload_file(os.path.join(root,file),BUCKET_NAME,file)
else:
print("no files found")
print ("data available")
РЕДАКТИРОВАТЬ:
import os
thePath = os.getcwd()
theFiles = list(os.listdir(thePath))
theDict = dict()
for something in theFiles: #Calculate size for all files here.
theStats = os.stat(something)
theDict[something] = theStats
for item in theDict:
if theDict[item].st_size > 1020:
print("File: {}, size greater than 1020, Uploading to s3 ..".format(item))
s3C.upload_file(os.path.join(root,file),BUCKET_NAME,file)
else:
print("File {}, size less than 1020".format(item))
ВЫХОД (из моего dir
и с комментариями s3C.upload_file()
метод:
File: .idea, size greater than 1020, Uploading to s3 ..
File: celebs.jpg, size greater than 1020, Uploading to s3 ..
File data.csv, size less than 1020
File: dum.jpg, size greater than 1020, Uploading to s3 ..
File: dummy.jpg, size greater than 1020, Uploading to s3 ..
File example2.csv, size less than 1020