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

#!/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 .
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Compare current date on calendar with date format file name Fioravanti 1 214 Mar-26-2024, 08:23 AM
Last Post: Pedroski55
  get list of dates in past month, current and upcoming month jacksfrustration 4 544 Feb-03-2024, 06:37 PM
Last Post: deanhystad
  Python date format changes to date & time 1418 4 588 Jan-20-2024, 04:45 AM
Last Post: 1418
  Trying to get year not the entire year & time mbrown009 2 883 Jan-09-2023, 01:46 PM
Last Post: snippsat
  Python Resampling: How do I obtain the value of the last week of the month? JaneTan 2 1,009 Dec-12-2022, 12:49 AM
Last Post: JaneTan
  Date format and past date check function Turtle 5 4,233 Oct-22-2021, 09:45 PM
Last Post: deanhystad
  Appropriate data-structure / design for business-day relations (week/month-wise) sx999 2 2,799 Apr-23-2021, 08:09 AM
Last Post: sx999
  How to add previous date infront of every unique customer id's invoice date ur_enegmatic 1 2,227 Feb-06-2021, 10:48 PM
Last Post: eddywinch82
  code to read files in folders and transfer the file name, type, date created to excel Divya577 0 1,856 Dec-06-2020, 04:14 PM
Last Post: Divya577
  How to add date and years(integer) to get a date NG0824 4 2,855 Sep-03-2020, 02:25 PM
Last Post: NG0824

Forum Jump:

User Panel Messages

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