Latest web development tutorials

Python os.chflags () method

Python File (File) method Python OS file / directory methods


Outline

Mark os.chflags () method is used to set the path for the digital signature. Multiple tags can be combined using OR.

Supported only under Unix.

grammar

chflags () method syntax is as follows:

os.chflags(path, flags)

parameter

  • path - the path name of the file or directory path.

  • flags - can be the following values:

    • stat.UF_NODUMP: Non-dump file
    • stat.UF_IMMUTABLE: file is read-only
    • stat.UF_APPEND: only the additional content file
    • stat.UF_NOUNLINK: File can not be deleted
    • stat.UF_OPAQUE: opaque directory, you need to see through the joint stack
    • stat.SF_ARCHIVED: you can archive files (super user can be set)
    • stat.SF_IMMUTABLE: file is read-only (super user can be set)
    • stat.SF_APPEND: files can only the additional content (super user can be set)
    • stat.SF_NOUNLINK: file is not deleted (super user can be set)
    • stat.SF_SNAPSHOT: snapshot file (super user can be set)

return value

This method has no return value.

Examples

The following example demonstrates chflags () method of use:

#!/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 above program output is:

返回值: None

Python File (File) method Python OS file / directory methods