YouTip LogoYouTip

Python3 Os Chflags

# Python3.x Python3 os.chflags() Method [![Image 3: Python3 OS File/Directory Methods](#) Python3 OS File/Directory Methods](#) * * * ### Overview The `os.chflags()` method is used to set the flags of a path to numeric flags. 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 name 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:** 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: ## Example #!/usr/bin/python3 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 outputs the following result: Return value: None [![Image 4: Python3 OS File/Directory Methods](#) Python3 OS File/Directory Methods](#)
← Python3 Os ChflagsPython3 File Writelines β†’