I am trying to write and save a file but the following error is raised by the python script:
OSError: [Errno 22] Invalid argument: 'C:/Export/ixxxx/izzzzz_2015-05-12 17:00:00.shp
What is wrong with the path? The directory exists.
In Windows, you can have a colon immediately after the volume name (C:), but not anywhere else in the path. You'll need to replace the colons with another character. I would use the - character, to keep it consistent with your date format. As a matter of personal preference, I would probably also replace the space in the filename with a -.
See the following example:
>>> pathname = 'C:/Temp' # Change this to your pathname.
>>> filename = 'izzzzz_2015-05-12 17:00:00.shp'
>>> filename = filename.replace(':', '-').replace(' ', '-')
>>> print('{}/{}'.format(pathname, filename))
C:/Temp/izzzzz_2015-05-12-17-00-00.shp
>>> with open('{}/{}'.format(pathname, filename), 'w') as f:
... pass
...
>>>
/in a pathname in Windows in a Python script.