[Python-bugs-list] [Bug #116720] function to open a file and create intermediate directories
noreply@sourceforge.net
noreply@sourceforge.net
Thu, 12 Oct 2000 09:24:57 -0700
Bug #116720, was updated on 2000-Oct-12 09:24
Here is a current snapshot of the bug.
Project: Python
Category: Modules
Status: Open
Resolution: None
Bug Group: Feature Request
Priority: 5
Summary: function to open a file and create intermediate directories
Details: A function would be useful (maybe available in the
os module), that opens a file for writing and creates
all necessary intermediate directories. Here is the
Python function that does exactly that:
def forceopen(name, filemode, dirmode=0777):
try:
return open(name, filemode)
except IOError, e:
if e[0] != 2: # didn't work for some other reason
raise
lastsep = name.rfind(os.sep)
if lastsep == -1:
raise
os.makedirs(name[:lastsep], dirmode)
return open(name, filemode)
For detailed info, follow this link:
http://sourceforge.net/bugs/?func=detailbug&bug_id=116720&group_id=5470