I think/hope this a an easy question that I just can't find the answer to - how do I create a directory where the title contains a colon? I'm scraping data from a website with variables for section and year, and creates a directory:
if 'C:/Path/Data/%s' % stat:
directory = 'C:/Path/Data/%s' % stat
else:
directory = 'C:/Path/Data/%s' % stat.replace('/', ' ')
if not os.path.exists(directory):
try:
os.makedirs(directory)
except OSError as e:
if not e.errno != errno.EEXIST:
raise
I have some error handling in there based on what's coming back. I had to bring in errno
to skip the section that was erring. I want to bring in that data however - and I believe the issue is the title of the section, and thus the directory, contains a :
in a directory like:
/Year: some_data/
I receive this error:
OSError: [Errno 22] Invalid argument:
Failed with OSError
My question is - how do I create or handle the creation of a directory with a :
in the title? I'm just skipping over it for now.
I apologize if this is a duplicate but I couldn't find anything specifically. I'm running python 3.6 in Jupyter Notebook on Windows 10. Thank you.