Creating folders dynamically with year/month/date - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Creating folders dynamically with year/month/date (/thread-5687.html) |
Creating folders dynamically with year/month/date - sritsv - Oct-16-2017 Hello Team, Below is the scenario, i need help in S3 using python. In S3 have a path till Table level manually created, <Bucket-Name> / <Subject-Area> / < Table > / <Year> / <Month>/ <Date> /<keyname> But is there a way in python , i can dynamically create , Year/Month/Date . my version of code to retrieve the folder/sub level. Im cautious , not using the word "folder" here, as there is no concept of "folder" in S3. #!/usr/bin/python import boto3 import sys import os import boto.ec2 from boto.s3.key import Key import boto.s3.connection bucket = sys.argv[1] prefix = sys.argv[2] client = boto3.client('s3') result = client.list_objects(Bucket=bucket, Prefix=prefix, Delimiter='/') for o in result.get('CommonPrefixes'): print 'folder structure : ', o.get('Prefix') Please correct if the above approach is wrong or a better way . |