The os.lchflags()
method is used to set the flag of the path to the numeric flags. It does not follow symbolic links, unlike chflags()
. We have listed some path flags that can be used according to our needs. For instance, when UF_NODUMP
is set, it will delete or dump the specified file. Similarly, when UF_IMMUTABLE
is set, it allows a file in read-only mode.
Flag | Description |
UF_NODUMP | Do not dump the mentioned file. |
UF_IMMUTABLE | Read only, file may not be changed. |
UF_APPEND | File may only be appended to. |
UF_NOUNLINK | File cannot be deleted or renamed. |
UF_OPAQUE | Opaque Directory, when viewed through the union stack. |
SF_ARCHIVED(Super User allowed) | File may only be archived. |
SF_IMMUTABLE | File may not be changed. |
SF_APPEND | File may only be appended to. |
SF_NOUNLINK | File may not be deleted or renamed. |
SF_SNAPSHOT | File is a snapshot file. |
os.lchflags(path, flags)
It takes the following argument values.
path
: This is an object that represents a valid system path.flags
: Flag types are listed in the table above.It does not return any value.
In the following code snippet, we are going to discuss the os.lchflags()
method in detail.
# importing OS and SYS modules # in current program import os,stat # Path path = "employee.csv" fd = os.open(path, os.O_CREAT | os.O_RDWR) # Taking os.UF_NODUMP as flag value #flag = os.UF_IMMUTABLE # Close opened file os.close(fd) # invoking lchflags() function os.lchflags(path, stat.UF_IMMUTABLE) print("Flag Changed Successfully!")
"employee.csv"
to a path variable.open()
method from the os
module to open the above mentioned file in the read and write mode (os.O_RDWR)
. We create this if it does not exist in the module.lchflags()
function to change the path flags of the above-loaded file.RELATED TAGS
CONTRIBUTOR
View all Courses