Skip to content

Commit e4e81b6

Browse files
committed
Add mkdir -p functionality using a try loop and file exists exception (mkdir_p)
1 parent a23d402 commit e4e81b6

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

nipype/utils/filemanip.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import os
1414
import re
1515
import shutil
16+
import errno
1617

1718
import numpy as np
1819

@@ -430,3 +431,13 @@ def write_rst_dict(info, prefix=''):
430431
for key, value in sorted(info.items()):
431432
out.append(prefix + '* ' + key + ' : ' + str(value))
432433
return '\n'.join(out)+'\n\n'
434+
435+
436+
def mkdir_p(path):
437+
try:
438+
os.makedirs(path)
439+
except OSError as exc:
440+
if exc.errno == errno.EEXIST and os.path.isdir(path):
441+
pass
442+
else:
443+
raise

0 commit comments

Comments
 (0)