10 examples of 'os.mkdir in python' in Python

Every line of 'os.mkdir in python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
424def mkdir(path,root=None,mode=None):
425 '''create a new directory in the root directory
426
427 create a directory at *path* and any necessary parents (i.e. ``mkdir -p``).
428 Default mode is read/write/execute for \'user\' and \'group\', and then
429 read/execute otherwise.
430
431 Args:
432 path (str): string name of the new directory.
433 root (str, default=None): path at which to build the new directory.
434 mode (str, default=None): octal read/write permission [default: 0o775].
435
436 Returns:
437 string absolute path for new directory.
438 '''
439 if mode is None: mode = MODE
440 if not root: root = os.curdir
441 newdir = os.path.join(root,path)
442 absdir = os.path.abspath(newdir)
443 import errno
444 try:
445 os.makedirs(absdir,mode)
446 return absdir
447 except OSError:
448 err = sys.exc_info()[0]
449 if (err.errno != errno.EEXIST) or (not os.path.isdir(absdir)):
450 raise
50def mkdirP(d):
51 try:
52 os.makedirs(d)
53 except OSError, err:
54 if err.errno != errno.EEXIST:
55 raise
41def mkdir(path):
42 try:
43 os.makedirs(path)
44 return True
45 except OSError:
46 return False
105def makedirs(name, mode=511):
106 head, tail = path.split(name)
107 if not tail:
108 head, tail = path.split(head)
109 if head and tail and not path.exists(head):
110 try:
111 makedirs(head, mode)
112 except OSError as e:
113 if e.errno != errno.EEXIST:
114 raise
115
116 if tail == curdir:
117 return
118 mkdir(name, mode)
30def mkdir(path):
31 if not os.path.exists(path):
32 os.makedirs(path)
33 if not os.path.isdir:
34 raise OSError("'%r' is not a path" % path)
88def mkdir(self):
89 """make a directory on this path (including all needed intermediate directories), if this
90 path doesn't already exist"""
91 if not self.exists():
92 os.makedirs(self.path)
248def mkdir(path: AnyStr, mode: int = 0o777) -> None: pass
146def mkdirs(*args: Path) -> None:
147 for dir in args:
148 dir.mkdir(parents=True, exist_ok=True)
6def mkdir_p(dirname):
7 try: os.makedirs(dirname)
8 except FileExistsError: pass
116def mkdir_p(path):
117 """Make directories recursively.
118
119 Source: http://stackoverflow.com/a/600612
120
121 :param path: path to create
122 :type path: string
123
124 """
125 try:
126 os.makedirs(path)
127 except OSError as exc: # Python >2.5
128 if exc.errno == errno.EEXIST and os.path.isdir(path):
129 pass
130 else:
131 raise

Related snippets