Easy Tutorial
❮ Ref Math Inf Python Mongodb Sort ❯

Python3 os.lchflags() Method

Python3 OS File/Directory Methods


Overview

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

This method is only supported on Unix systems.

Syntax

The syntax for the lchflags() method is as follows:

os.lchflags(path, flags)

Parameters

-

path -- The file path for which to set the flags.

-

flags -- Can be a combination of one or more flags, separated by "|":

-

UF_NODUMP: Non-dump file

-

UF_IMMUTABLE: File is read-only

-

UF_APPEND: File can only have data appended

-

UF_NOUNLINK: File cannot be deleted

-

UF_OPAQUE: Directory is opaque, requires union stack to view

-

SF_ARCHIVED: Archivable file (superuser can set)

-

SF_IMMUTABLE: File is read-only (superuser can set)

-

SF_APPEND: File can only have data appended (superuser can set)

-

SF_NOUNLINK: File cannot be deleted (superuser can set)

-

SF_SNAPSHOT: Snapshot file (superuser can set)

Return Value

This method does not return any 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 flags
ret = os.lchflags(path, os.UF_IMMUTABLE )

print ("File flags modified successfully!!")

Executing the above program will output:

File flags modified successfully!!

Python3 OS File/Directory Methods

❮ Ref Math Inf Python Mongodb Sort ❯