I get a different error (putting permission issues aside) when I try a stripped down version of what you're doing here:
>>> import os
>>> path = "foo/bar/file.txt"
>>> os.makedirs(path)
>>> with open(path, "w") as f:
... f.write("HOWDY!")
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IOError: [Errno 21] Is a directory: 'foo/bar/file.txt'
Note that when you do this:
# Check if directory exists
if not os.path.exists(completeName):
os.makedirs(completeName)
...you're creating a directory that has a name that's both the path you want (good) and the name of the file you're trying to create. Pass the pathname only to makedirs()
and then create the file inside that directory when you've done that.