for month in range(1, 13): folder = folder = f'{year}-{month:0>2}' os.makedirs(os.path.join('.', folder))Thanks Buran. That worked.
Can you explain the code to me and, more importantly, your thought process to arrive at this code?
* How do I get past the point of just staring at a blank screen having no real idea how to start?
* Where did month come from? It's not a variable like 'year' which uses the datetime module.
* Why is the f-string using 2 folder-equals (folder = folder = f')? I've never seen that.
* What are you joining with os..join? What is the '.' pointing to, current folder? If so, where's the backslash (.\)?
Thanks for the help.
I quickly (for me ) coded up a script to create a complete folder-subfolder structure for a tax year. This will be a yearly time saver and I'm quite proud of myself
Phil
BTW, for anybody here for future reference.
required dependencies:
import os import datetime year = datetime.now().yearThe above forLoop replaces these lines of code:
os.makedirs('.\\' + str(year) + '-01') os.makedirs('.\\' + str(year) + '-02') os.makedirs('.\\' + str(year) + '-03') os.makedirs('.\\' + str(year) + '-04') os.makedirs('.\\' + str(year) + '-05') os.makedirs('.\\' + str(year) + '-06') os.makedirs('.\\' + str(year) + '-07') os.makedirs('.\\' + str(year) + '-08') os.makedirs('.\\' + str(year) + '-09') os.makedirs('.\\' + str(year) + '-10') os.makedirs('.\\' + str(year) + '-11') os.makedirs('.\\' + str(year) + '-12')Phil