YouTip LogoYouTip

Os Lchflags

# Python2.x Python os.lchflags() Method [![Image 3: Python File Methods](#) Python 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 does not follow symbolic links. It is only supported on Unix. ### 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 be appended to. * **UF_NOUNLINK:** File cannot be deleted. * **UF_OPAQUE:** Directory is opaque and must be viewed through a union stack. * **SF_ARCHIVED:** Archived file (can be set by superuser). * **SF_IMMUTABLE:** File is read-only (can be set by superuser). * **SF_APPEND:** File can only be appended to (can be set by superuser). * **SF_NOUNLINK:** File cannot be deleted (can be set by superuser). * **SF_SNAPSHOT:** Snapshot file (can be set by superuser). ### Return Value This method does not return a value. ### Example The following example demonstrates the use of the lchflags() method: #!/usr/bin/python# -*- coding: UTF-8 -*-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!!" The output of executing the above program is: File flags modified successfully!! [![Image 4: Python File Methods](#) Python OS File/Directory Methods](#)
← Os LchownOs Getcwdu β†’