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

Python3 os.lchflags() Method

Python3 os.lchflags() Method

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


Overview

The os.lchflags() method sets the flags of a path to numeric flags, similar to chflags(), but without following symbolic links.

Only supported on Unix.

Syntax

The **lchflags()** method syntax is as follows:


os.lchflags(path, flags)

Parameters

-

UF_NODUMP: Do not dump the file

-

UF_IMMUTABLE: The file is read-only

-

UF_APPEND: The file may only be appended to

-

UF_NOUNLINK: The file may not be deleted

-

UF_OPAQUE: The directory is opaque and must be viewed through the union stack

-

SF_ARCHIVED: The file is archived (superuser can set)

-

SF_IMMUTABLE: The file is read-only (superuser can set)

-

SF_APPEND: The file may only be appended to (superuser can set)

-

SF_NOUNLINK: The file may not be deleted (superuser can set)

-

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 lchflags() method:


#!/usr/bin/python3

import os, sys

# Open file
path = "/var/www/html/foo.txt"
fd = os.open( path, os.O_RDWR|os.O_CREAT )

# Close file
os.close( fd )

# Modify file marker
ret = os.lchflags(path, os.UF_IMMUTABLE )

print ("修改文件标记成功!!")

The output of the above program is:


修改文件标记成功!!

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