描述
方法chflags()將路徑標誌設置為數字標誌。標誌可以采用下麵描述的各種值的組合(按位或)。
注意− 此方法適用於 Python 2.6 版本以上。大多數標誌隻能由 super-user 更改。
用法
以下是語法chflags()方法 -
os.chflags(path, flags)
參數
path- 這是要更改到新位置的目錄的完整路徑。
flags- 指定的標誌是通過對以下值進行 OR 運算形成的 -
os.UF_NODUMP− 不要轉儲文件。
os.UF_IMMUTABLE− 文件不得更改。
os.UF_APPEND− 文件隻能附加到。
os.UF_NOUNLINK− 文件不得重命名或刪除。
os.UF_OPAQUE− 通過聯合堆棧查看時,該目錄是不透明的。
os.SF_ARCHIVED− 文件可能已存檔。
os.SF_IMMUTABLE− 文件不得更改。
os.SF_APPEND− 文件隻能附加到。
os.SF_NOUNLINK− 文件不得重命名或刪除。
os.SF_SNAPSHOT− 文件為快照文件。
返回值
此方法不返回任何值。
示例
下麵的例子展示了 chflags() 方法的用法。
#!/usr/bin/python3
import os
path = "/tmp/foo.txt"
# Set a flag so that file may not be renamed or deleted.
flags = os.SF_NOUNLINK
retval = os.chflags( path, flags)
print ("Return Value:%s" % retval)
結果
當我們運行上述程序時,它會產生以下結果 -
Return Value:None
相關用法
- Python 3 os.chmod()用法及代碼示例
- Python 3 os.chroot()用法及代碼示例
- Python 3 os.chdir()用法及代碼示例
- Python 3 os.chown()用法及代碼示例
- Python 3 os.close()用法及代碼示例
- Python 3 os.closerange()用法及代碼示例
- Python 3 os.fstatvfs()用法及代碼示例
- Python 3 os.minor()用法及代碼示例
- Python 3 os.unlink()用法及代碼示例
- Python 3 os.major()用法及代碼示例
- 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.makedirs()用法及代碼示例
- Python 3 os.utime()用法及代碼示例
- Python 3 os.tcgetpgrp()用法及代碼示例
注:本文由純淨天空篩選整理自 Python 3 - os.chflags() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。