YouTip LogoYouTip

Os Chflags

# Python2.x Python os.chflags() Method [![Image 3: Python File(Files) Method](#) Python OS File/Directory Methods](#) * * * ### Overview The os.chflags() method is used to set the flags of a path to a numeric value. Multiple flags can be combined using the OR operator. It is only supported for use on Unix systems. ### Syntax The syntax for the **chflags()** method is as follows: os.chflags(path, flags) ### Parameters * **path** -- The file path or directory path. * **flags** -- Can be one of the following values: * **stat.UF_NODUMP:** Non-dump file * **stat.UF_IMMUTABLE:** File is read-only * **stat.UF_APPEND:** File can only be appended to * **stat.UF_NOUNLINK:** File cannot be deleted * **stat.UF_OPAQUE:** Directory is opaque and must be viewed through a union stack * **stat.SF_ARCHIVED:** Archived file (can be set by superuser) * **stat.SF_IMMUTABLE:** File is read-only (can be set by superuser) * **stat.SF_APPEND:** File can only be appended to (can be set by superuser) * **stat.SF_NOUNLINK:** File cannot be deleted (can be set by superuser) * **stat.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 chflags() method: #!/usr/bin/python# -*- coding: UTF-8 -*-import os,stat path = "/tmp/foo.txt"# Set flags for the file to make it non-renamable and non-deletable flags = stat.SF_NOUNLINK retval = os.chflags( path, flags)print "Return value: %s" % retval Executing the above program produces the following output: Return value: None [![Image 4: Python File(Files) Method](#) Python OS File/Directory Methods](#)
← Os ChflagsOs Access β†’