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

Python os.chflags() method

Python os.chflags() method

Python File methods Python 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:


#!/usr/bin/python
# -*- coding: UTF-8 -*-

import os,stat

path = "/tmp/foo.txt"

# Set a flag for the file so that it cannot be renamed or deleted
flags = stat.SF_NOUNLINK
retval = os.chflags( path, flags)
print "返回值: %s" % retval

The output of the above program is:


返回值: None

Python File methods Python OS file/directory methods