Python os.lchflags() Method
Python OS File/Directory Methods
Overview
The os.lchflags() method is used to set the flags of a path to numeric flags, similar to chflags(), but without following symbolic links.
Only supported on Unix.
Syntax
lchflags()The method syntax is as follows:
os.lchflags(path, flags)
Parameters
path-- File path for which to set the flags
flags-- Can be one or more flags combined, with multiple flags 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, needs to be viewed through the union stack
SF_ARCHIVED:Archive 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 has no return value.
Example
The following example demonstrates the usage of the lchflags() method:
#!/usr/bin/python # -*- coding: UTF-8 -*- 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 of the above program is:
File marker modified successfully!!Other Extensions