Python | os.lchflags() method

OS module in Python provides functions for interacting with the operating system. OS comes under Python’s standard utility modules. This module provides a portable way of using operating system dependent functionality.

os.lchflags() method in Python used to set the flags of the specified path to the numeric flags,
This method is similar to os.chflags() method but it does not follows symbolic links.

Note: This method is only available on Unix platforms.



Syntax: os.lchflag(path, flags)

Parameters:
path: A path-like object representing a valid system path. It can be a string object or bytes object representing a path.
flags: A numeric value representing path flag or it takes combination (bitwise OR) of the following values defined in stat module –

 os.UF_NODUMP – Don’t dump the file.
 os.UF_IMMUTABLE – File may not be changed(read-only).
 os.UF_APPEND – File may only be appended to.
 os.UF_OPAQUE – Directory is opaque, view through a union stack.
 os.UF_NOUNLINK – File may not be renamed or deleted.
 os.UF_COMPRESSED – File is stored compressed
 os.UF_HIDDEN – File should not be displayed in a GUI
 os.SF_ARCHIVED – File may be archived.(super user can be set)
 os.SF_IMMUTABLE – File may not be changed. (super user can be set)
 os.SF_APPEND – File may only be appended to. (super user can be set)
 os.SF_NOUNLINK – File may not be renamed or deleted.(super user can be set)
 os.SF_SNAPSHOT – File is a snapshot file. (super user can be set)

Return type: This method doesn’t return any value.

Code: Use of os.lchflags() method

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python3 program to explain os.lchflags() method
  
# importing os library
import os
  
# Path
path = "GeeksForGeeks/sample.txt"
  
# Flag value
flag = os.UF_NODUMP
  
# Change the flag of the
# specified path using
# os.lchflags() method
os.lchflags(path, flag)
  
print("Flag changed successfully")

chevron_right


Output:

Flag changed successfully


My Personal Notes arrow_drop_up

self motivated and passionate programmer

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.