Python os.chflags() Method

Python File(文件) 方法Python OS File/Directory Methods


Overview

The os.chflags() method is used to set the flags of a path to numeric flags. Multiple flags can be combined using OR.

Only supported on Unix.

Syntax

chflags()The method syntax is as follows:

os.chflags(path, flags)

Parameters

  • path-- File name path or directory path.

  • flags-- Can be one of the following values:

    • stat.UF_NODUMP:Non-dump file
    • stat.UF_IMMUTABLE:File is read-only
    • stat.UF_APPEND:File can only be appended to
    • stat.UF_NOUNLINK:File cannot be deleted
    • stat.UF_OPAQUE:Directory is opaque, and needs to be viewed through a union stack
    • stat.SF_ARCHIVED:Archivable file (settable by superuser)
    • stat.SF_IMMUTABLE:File is read-only (settable by superuser)
    • stat.SF_APPEND:File can only be appended to (settable by superuser)
    • stat.SF_NOUNLINK:File cannot be deleted (settable by superuser)
    • stat.SF_SNAPSHOT:Snapshot file (settable by superuser)

Return Value

This method has no return value.

Examples

The following example demonstrates the usage of the chflags() method:

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

import os,stat

path = "/tmp/foo.txt"

# 为文件设置标记,使得它不能被重命名和删除
flags = stat.SF_NOUNLINK
retval = os.chflags( path, flags)
print "返回值: %s" % retval

The output of the above program is:

返回值: None

Python File(文件) 方法Python OS File/Directory Methods

Other Extensions