Bottom Page

Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Creating folders dynamically with year/month/date
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. Tongue

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 .
Larz60+ wrote Oct-16-2017, 03:54 PM:
Please use code tags, see BBCODE
also use shift-ctrl-v when pasting to preserve indentation

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  sub-folders in folders from text line jenost 1 41 Mar-31-2020, 07:16 AM
Last Post: ndc85430
  Learning Python in a month MuhammadNauman 1 321 Jul-17-2019, 11:53 AM
Last Post: metulburr
  Substracting today's date from a date in column of dates to get an integer value firebird 1 354 Jul-04-2019, 06:54 PM
Last Post: Axel_Erfurt
  How to change existing date to current date in a filename? shankar455 1 465 Apr-17-2019, 01:53 PM
Last Post: snippsat
  Date format conversion "/Date(158889600000)/" lbitten 2 503 Nov-29-2018, 02:14 PM
Last Post: Larz60+
  How to get all the data for the current month in ms Access using python? aeo03 1 563 Nov-07-2018, 08:21 PM
Last Post: micseydel
  Creating multiple folders and other questions coder2be 2 677 Aug-19-2018, 06:59 PM
Last Post: coder2be
  Help creating a class instance dynamically Kotevski 9 1,182 Aug-17-2018, 05:23 AM
Last Post: Gribouillis
  dynamically creating a subclass sidereal 2 1,538 Jan-04-2018, 11:10 PM
Last Post: Gribouillis
  Calculating what year it is when you are 100 years old dankim9000 2 5,349 Apr-26-2017, 08:03 PM
Last Post: dankim9000

Forum Jump:

Users browsing this thread: 1 Guest(s)