描述
方法makedirs()是遞歸目錄創建函數。與 mkdir() 類似,但使所有 intermediate-level 目錄都包含葉目錄。
默認模式是 0o777(八進製)。在某些係統上,模式被忽略。在使用它的地方,首先屏蔽掉當前的 umask 值。
如果exist_ok 為False(默認值),如果目標目錄已經存在,則會引發OSError。
用法
以下是語法makedirs()方法 -
os.makedirs(path[, mode])
參數
path- 這是路徑,需要遞歸創建。
mode- 這是要給出的目錄的模式。
返回值
此方法不返回任何值。
示例
下麵的例子展示了 makedirs() 方法的用法。
#!/usr/bin/python3
import os, sys
# Path to be created
path = "d:/tmp/home/monthly/daily"
os.makedirs( path, 493 ) #decimal equivalent of 0755 used on Windows
print ("Path is created")
結果
當我們運行上述程序時,它會產生以下結果 -
Path is created
相關用法
- Python 3 os.makedev()用法及代碼示例
- Python 3 os.major()用法及代碼示例
- Python 3 os.minor()用法及代碼示例
- Python 3 os.mknod()用法及代碼示例
- Python 3 os.mkdir()用法及代碼示例
- Python 3 os.mkfifo()用法及代碼示例
- Python 3 os.fstatvfs()用法及代碼示例
- Python 3 os.close()用法及代碼示例
- Python 3 os.unlink()用法及代碼示例
- Python 3 os.rmdir()用法及代碼示例
- Python 3 os.fdopen()用法及代碼示例
- Python 3 os.fdatasync()用法及代碼示例
- Python 3 os.isatty()用法及代碼示例
- Python 3 os.rename()用法及代碼示例
- Python 3 os.walk()用法及代碼示例
- Python 3 os.renames()用法及代碼示例
- Python 3 os.utime()用法及代碼示例
- Python 3 os.tcgetpgrp()用法及代碼示例
- Python 3 os.statvfs()用法及代碼示例
- Python 3 os.lchown()用法及代碼示例
注:本文由純淨天空篩選整理自 Python 3 - os.makedirs() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。