Python3 os.lchflags() Method
Python3 OS File/Directory Methods
Overview
The os.lchflags() method is used to set the path's flags as numeric flags, similar to chflags(), but without following symbolic links.
Only supported on Unix.
Syntax
lchflags()The syntax of the method is as follows:
os.lchflags(path, flags)
Parameters
path-- The file path to set the flags
flags-- It can be composed of one or more flags, with multiple ones separated by "|":
UF_NODUMP:Non-dump file
UF_IMMUTABLE:File is read-only
UF_APPEND:File can only be appended to
UF_NOUNLINK:File cannot be deleted
UF_OPAQUE:Directory is opaque, and needs to be viewed through a union stack
SF_ARCHIVED:Archivable file (settable by superuser)
SF_IMMUTABLE:File is read-only (settable by superuser)
SF_APPEND:File can only be appended to (settable by superuser)
SF_NOUNLINK:File cannot be deleted (settable by superuser)
SF_SNAPSHOT:Snapshot file (settable by superuser)
Return Value
This method does not return a value.
Example
The following example demonstrates the usage of the lchflags() method:
#!/usr/bin/python3
import os, sys
# 打开文件
path = "/var/www/html/foo.txt"
fd = os.open( path, os.O_RDWR|os.O_CREAT )
# 关闭文件
os.close( fd )
# 修改文件标记
ret = os.lchflags(path, os.UF_IMMUTABLE )
print ("修改文件标记成功!!")
The output result after executing the above program is:
Successfully modified file marker!!Other Extensions