Reputation: 11
Sorry if this is obvious; I'm new to Rpi and Linux in general. Im trying to create code for a timelapse camera such that when it turns on, it starts taking images and saves them to a folder.
The part I cant find any information on (or if its possible) is how to generate a new(unique) subfolder for each time the code starts running, and then send the new photos to that location?
The actual photo taking code is super simple:
for i in range(numphotos):
camera.capture('/home/pi/Pictures/image{0:06d}.jpg'.format(i))
sleep(secondsinterval)
My current solution is to just dump them all in the same folder with a unique date and time stamp so that if it has to restart, it has a clear beginning and ending:
dateraw= datetime.datetime.now()
datetimeformat = dateraw.strftime("%Y-%m-%d_%H:%M")
for i in range(numphotos):
camera.capture('/home/pi/Pictures/'+ datetimeformat + '_{0:06d}.jpg'.format(i))
sleep(secondsinterval)
but as ive said, instead of directing it to the pictures folder, is there any way I can write code so it generates a unique folder (maybe based on the date) and sends the images there?
Upvotes: 1
Views: 62
Reputation: 11
Turns out it was super simple.
All that was needed was to create a folder at the start time using os.mkdir()
, and simply direct the code to it:
dateRaw= datetime.datetime.now()
startDateTimeFormat = dateRaw.strftime("%Y-%m-%d_%H:%M:%S")
os.mkdir('/home/timelapse1/Pictures/' + startDateTimeFormat)
for i in range(numPhotos):
camera.capture('/home/timelapse1/Pictures/' + startDateTimeFormat +'/{0:06d}.jpg'.format(i))
sleep(secondsInterval)
I wont mark this as the solution just incase there is still something i'm missing, but it is working well.
Upvotes: 0