The problem is: I have to create a file in an automatically way into some folder which have been automatically created before.
Let me explain better. First I post the code used to create the folder...
import os
from datetime import datetime
timestr = datetime.now().strftime("%Y%m%d-%H%M%S-%f")
now = datetime.now()
newDirName = now.strftime("%Y%m%d-%H%M%S-%f")
folder = os.mkdir('C:\\Users\\User\\Desktop\\' + newDirName)
This code will create a folder on Desktop with timestamp (microseconds included to make it as unique as possible..) as name.
Now I would like to create also a file (for example a txt) inside the folder. I already have the code to do it...
file = open('B' + timestr, 'w')
file.write('Exact time is: ' + timestr)
file.close()
How can I "combine" this together ? First create the folder and, near immediately, the file inside it?
Thank you. If it's still not clear, feel free to ask.