Python3 os.chflags() Method
Python3 OS File/Directory Methods
Overview
The os.chflags() method sets the flags of a path to numeric flags. Multiple flags can be combined with OR.
Only supported on Unix.
Syntax
The **chflags()** method syntax is as follows:
os.chflags(path, flags)
Parameters
-
path -- A file path or a directory path.
-
flags -- Can be one of the following values:
- stat.UF_NODUMP: Do not dump the file
- stat.UF_IMMUTABLE: The file is read-only
- stat.UF_APPEND: The file may only be appended to
- stat.UF_NOUNLINK: The file may not be deleted
- stat.UF_OPAQUE: The directory is opaque and must be viewed through the union stack
- stat.SF_ARCHIVED: The file is archived (superuser can set)
- stat.SF_IMMUTABLE: The file is read-only (superuser can set)
- stat.SF_APPEND: The file may only be appended to (superuser can set)
- stat.SF_NOUNLINK: The file may not be deleted (superuser can set)
- stat.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 chflags() method:
Example
#!/usr/bin/python3
import
os
,
stat
path
=
"/tmp/foo.txt"
Set flags on the file so that it cannot be renamed or deleted
flags
=
stat
.
SF_NOUNLINK
retval
=
os
.
chflags
(
path
,
flags
)
(
"Return value: %s"
% retval
)
The output of the above program is:
返回值: None