Update all new Tasks
This commit is contained in:
parent
00a190b0a6
commit
91df62d461
5697 changed files with 93386 additions and 804 deletions
23
Task/Make-directory-path/Python/make-directory-path-1.py
Normal file
23
Task/Make-directory-path/Python/make-directory-path-1.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
from errno import EEXIST
|
||||
from os import mkdir, curdir
|
||||
from os.path import split, exists
|
||||
|
||||
def mkdirp(path, mode=0777):
|
||||
head, tail = split(path)
|
||||
if not tail:
|
||||
head, tail = split(head)
|
||||
if head and tail and not exists(head):
|
||||
try:
|
||||
mkdirp(head, mode)
|
||||
except OSError as e:
|
||||
# be happy if someone already created the path
|
||||
if e.errno != EEXIST:
|
||||
raise
|
||||
if tail == curdir: # xxx/newdir/. exists if xxx/newdir exists
|
||||
return
|
||||
try:
|
||||
mkdir(path, mode)
|
||||
except OSError as e:
|
||||
# be happy if someone already created the path
|
||||
if e.errno != EEXIST:
|
||||
raise
|
||||
Loading…
Add table
Add a link
Reference in a new issue