Reputation: 1
I'm trying to code a script in python that creates a folder entitled the current timestamp, but don't really know the syntax to do it. So far I have this:
timestamp = int(time.time()) #fetches timestamp
if not os.path.exists([timestamp]): #creates new folder titled the current timestamp
os.makedirs([timestamp])
os.chdir([timestamp]) #navigates to new folder
When I run this, I run into errors.
P.S. I am a beginner, please don't bite.
Upvotes: 0
Views: 41
Reputation: 74655
The timestamp needs to be converted to a str
ing. and then that str
ing need to be passed as the argument to the os
functions:
timestamp = str(int(time.time())) #fetches timestamp
if not os.path.exists(timestamp): #creates new folder titled the current timestamp
os.makedirs(timestamp)
os.chdir(timestamp) #navigates to new folder
Upvotes: 2