Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python3 os.chflags() Method

Python3 os.chflags() Method

Python3 OS File/Directory Methods 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

- **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

)

print

(

"Return value: %s"

% retval

)

The output of the above program is:


返回值: None

Python3 OS File/Directory Methods Python3 OS File/Directory Methods