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
  Prevention of deleting and creating folders kayak88 1 469 Mar-10-2025, 02:19 PM
Last Post: DeaD_EyE
  Compare current date on calendar with date format file name Fioravanti 1 1,885 Mar-26-2024, 08:23 AM
Last Post: Pedroski55
  get list of dates in past month, current and upcoming month jacksfrustration 4 1,658 Feb-03-2024, 06:37 PM
Last Post: deanhystad
  Python date format changes to date & time 1418 4 2,523 Jan-20-2024, 04:45 AM
Last Post: 1418
  Trying to get year not the entire year & time mbrown009 2 1,691 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 2,284 Dec-12-2022, 12:49 AM
Last Post: JaneTan
  Date format and past date check function Turtle 5 9,566 Oct-22-2021, 09:45 PM
Last Post: deanhystad
  Appropriate data-structure / design for business-day relations (week/month-wise) sx999 2 3,607 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,808 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 2,405 Dec-06-2020, 04:14 PM
Last Post: Divya577

Forum Jump:

User Panel Messages

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