Hello dear readers! Welcome back to another section of our tutorial on Python. In this tutorial guide, we are going to be studying about the Os lchflags() method.
Python os lchflags() method sets the flags of path to the numeric flags. This method does not follow symbolic links unlike the chflags() method.
Note - This method is introduced in Python version 2.6
Python os lchflags() method sets the flags of path to the numeric flags. This method does not follow symbolic links unlike the chflags() method.
Note - This method is introduced in Python version 2.6
Syntax
The following below is the syntax for Python Os lchflags() method -
os.lchflags(path, flags)
RECOMMENDED POST: Python os.chflags() Method with example
Parameter Details
- path - This is file path for which flags is to be set.
- flags - The flag specified are formed by OR'ing the below values -
- os.UF_NODUMP - Do not dump the file.
- os.UF_IMMUTABLE - The file may be static and not changed.
- os.UF_APPEND - The file may be appended to.
- os.UF_NOUNLINK - The file may not be renamed or deleted.
- os.UF_OPAQUE - The file directory is opaque when viewed through a union stack.
- os.SF_ARCHIVED - The file may be archived.
- os.SF_IMMUTABLE - The file may not be changed.
- os.SF_APPEND - The file may be appended to.
- os.SF_NOUNLINK - The file may not be deleted or renamed.
- os.SF_SNAPSHOT - It is a snapshot file.
Return Value
It does not return any value.
Example
The following below is a simple example -
#!/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!!"
Output
When the above code is executed, it will produce the following result -
Changed file flag successfully!!
RECOMMENDED POST: Python os.isatty() Method
Alright guys! This is where we are rounding up for this tutorial post. In our next tutorial, we are going to be studying about the Python OS lchmod() Method.
Feel free to ask your questions where necessary and i will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.
Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.
Thanks for reading and bye for now.
Feel free to ask your questions where necessary and i will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.
Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.
Thanks for reading and bye for now.