Python method lchflags() sets the flags of the path to the numeric flags. This method does not follow symbolic links, unlike chflags() method.
Here, flags may take a combination (bitwise OR) of the following values (as defined in the stat module) −
Note − This method has been introduced in Python 2.6
Following is the syntax for lchflags() method:
os.lchflags(path, flags)
This method does not return any value.
The following example shows the usage of lchflags() method.
#!/usr/bin/python import os, sys # Open a file path = "/var/www/html/foo.txt" fd = os.open( path, os.O_RDWR'os.O_CREAT ) # Close opened file os.close( fd ) # Now change the file flag. ret = os.lchflags(path, os.UF_IMMUTABLE ) print "Changed file flag successfully!!"
When we run the above program, it produces the following result:
Changed file flag successfully!!
Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.