描述
方法lchflags()將路徑標誌設置為數字標誌。與 chflags() 方法不同,此方法不遵循符號鏈接。從 Python 3.3 開始,這等效於 os.chflags(path, flags, follow_symlinks = False)。
在這裏,標誌可以采用以下值的組合(按位或)(在 stat 模塊中定義) -
UF_NODUMP− 不要轉儲文件。
UF_IMMUTABLE− 文件不得更改。
UF_APPEND− 文件隻能附加到。
UF_NOUNLINK− 文件不得重命名或刪除。
UF_OPAQUE− 通過聯合堆棧查看時,該目錄是不透明的。
SF_ARCHIVED− 文件可能已存檔。
SF_IMMUTABLE− 文件不得更改。
SF_APPEND− 文件隻能附加到。
SF_NOUNLINK− 文件不得重命名或刪除。
SF_SNAPSHOT− 文件為快照文件。
注意- 此方法已在 Python 2.6 中引入
用法
以下是語法lchflags()方法 -
os.lchflags(path, flags)
參數
path- 這是要設置標誌的文件路徑。
flags- 這可能是上述定義的標誌值的組合(按位或)。
返回值
此方法不返回任何值。在類 Unix 係統上可用
示例
下麵的例子展示了 lchflags() 方法的用法。
#!/usr/bin/python3
import os, sys
# Open a file
path = "/var/www/html/foo.txt"
fd = os.open( path, os.O_RDWR|os.O_CREAT )
# Close opened file
os.close( fd )
# Now change the file flag.
ret = os.lchflags(path, os.UF_IMMUTABLE )
print ("Changed file flag successfully!!")
結果
當我們運行上述程序時,它會產生以下結果 -
Changed file flag successfully!!
相關用法
- Python 3 os.lchown()用法及代碼示例
- Python 3 os.lchmod()用法及代碼示例
- Python 3 os.lstat()用法及代碼示例
- Python 3 os.lseek()用法及代碼示例
- Python 3 os.link()用法及代碼示例
- Python 3 os.listdir()用法及代碼示例
- Python 3 os.fstatvfs()用法及代碼示例
- Python 3 os.minor()用法及代碼示例
- Python 3 os.close()用法及代碼示例
- 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.lchflags() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。