YouTip LogoYouTip

Os Chflags

# Python2.x Python os.chflags() Method [![Image 3: Python File Methods](#) 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 OR. It is only supported 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, needs to be viewed through the union stack * **stat.SF_ARCHIVED:** Archivable 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 prevent it from being renamed or deleted flags = stat.SF_NOUNLINK retval = os.chflags( path, flags)print "Return value: %s" % retval Executing the above program outputs the following result: Return value: None [![Image 4: Python File Methods](#) Python OS File/Directory Methods](#)
← Os ChrootOs Chflags β†’