Python os.lchflags() method
Python OS file/directory methods
Overview
The os.lchflags() method sets the flags of a path to numeric flags, similar to chflags(), but without following symbolic links.
Only supported on Unix.
Syntax
The **lchflags()** method syntax is as follows:
os.lchflags(path, flags)
Parameters
-
path -- The path of the file whose flags are set
-
flags -- Can be a combination of one or more flags, separated by "|" when there are several:
-
UF_NODUMP: Do not dump the file
-
UF_IMMUTABLE: The file is read-only
-
UF_APPEND: The file may only be appended to
-
UF_NOUNLINK: The file may not be deleted
-
UF_OPAQUE: The directory is opaque and must be viewed through the union stack
-
SF_ARCHIVED: The file is archived (superuser can set)
-
SF_IMMUTABLE: The file is read-only (superuser can set)
-
SF_APPEND: The file may only be appended to (superuser can set)
-
SF_NOUNLINK: The file may not be deleted (superuser can set)
-
SF_SNAPSHOT: The file is a snapshot (superuser can set)
UF_NODUMP: Do not dump the file
-UF_IMMUTABLE: The file is read-only
-UF_APPEND: The file may only be appended to
-UF_NOUNLINK: The file may not be deleted
-UF_OPAQUE: The directory is opaque and must be viewed through the union stack
-SF_ARCHIVED: The file is archived (superuser can set)
-SF_IMMUTABLE: The file is read-only (superuser can set)
-SF_APPEND: The file may only be appended to (superuser can set)
-SF_NOUNLINK: The file may not be deleted (superuser can set)
-SF_SNAPSHOT: The file is a snapshot (superuser can set)
Return Value
This method has no return value.
Example
The following example demonstrates the use of the lchflags() method:
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os, sys
# Open file
path = "/var/www/html/foo.txt"
fd = os.open( path, os.O_RDWR|os.O_CREAT )
# Close file
os.close( fd )
# Modify file marker
ret = os.lchflags(path, os.UF_IMMUTABLE )
print "修改文件标记成功!!"
The output of the above program is:
修改文件标记成功!!