Python os.chflags() method definition and usage introduction (example analysis)

乌拉乌拉~
Release: 2018-08-17 14:45:09
Original
1672 people have browsed it

Today in this article we will take a look at the python os.chflags() method. In the next article we will introduce the chflags() in the python os module ) method introduces its definition and its functions and uses.

Overview

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

Only supports use under Unix.

Grammar

chflags() method syntax format is as follows:

os.chflags(path, flags)
Copy after login

Parameters

path -- File name path or directory path.

flags -- Can be the following values:

stat.UF_NODUMP: Non-dump file

stat.UF_IMMUTABLE: The file is read-only

stat .UF_APPEND: The file can only append content

stat.UF_NOUNLINK: The file cannot be deleted

stat.UF_OPAQUE: The directory is opaque and needs to be viewed through the joint stack

stat.SF_ARCHIVED: Yes Archive file (settable by super user)

stat.SF_IMMUTABLE: The file is read-only (settable by super user)

stat.SF_APPEND: The file can only append content (settable by super user)

stat.SF_NOUNLINK: The file cannot be deleted (can be set by the super user)

stat.SF_SNAPSHOT: Snapshot file (can be set by the super user)

(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"
# 为文件设置标记,使得它不能被重命名和删除
flags = stat.SF_NOUNLINK
retval = os.chflags( path, flags)
print "返回值: %s" % retval
Copy after login

The output result of executing the above program is:

返回值: None
Copy after login

The above is all the content of this article. I hope what I said and the examples I gave can be helpful to you.

For more related knowledge, please visit the Python tutorial column on the php Chinese website.

The above is the detailed content of Python os.chflags() method definition and usage introduction (example analysis). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template