Python| os.lchflags() 方法
Python中的OS 模块提供了与操作系统交互的功能。操作系统属于 Python 的标准实用程序模块。该模块提供了一种使用操作系统相关功能的可移植方式。
Python中的os.lchflags()
方法用于将指定路径的标志设置为数字标志,
此方法类似于os.chflags()
方法,但它不遵循符号链接。
注意:此方法仅适用于 Unix 平台。
Syntax: os.lchflag(path, flags)
Parameters:
path: A path-like object representing a valid system path. It can be a string object or bytes object representing a path.
flags: A numeric value representing path flag or it takes combination (bitwise OR) of the following values defined in stat module –
os.UF_NODUMP – Don’t dump the file.
os.UF_IMMUTABLE – File may not be changed(read-only).
os.UF_APPEND – File may only be appended to.
os.UF_OPAQUE – Directory is opaque, view through a union stack.
os.UF_NOUNLINK – File may not be renamed or deleted.
os.UF_COMPRESSED – File is stored compressed
os.UF_HIDDEN – File should not be displayed in a GUI
os.SF_ARCHIVED – File may be archived.(super user can be set)
os.SF_IMMUTABLE – File may not be changed. (super user can be set)
os.SF_APPEND – File may only be appended to. (super user can be set)
os.SF_NOUNLINK – File may not be renamed or deleted.(super user can be set)
os.SF_SNAPSHOT – File is a snapshot file. (super user can be set)
Return type: This method doesn’t return any value.
代码:使用os.lchflags()
方法
# Python3 program to explain os.lchflags() method
# importing os library
import os
# Path
path = "GeeksForGeeks/sample.txt"
# Flag value
flag = os.UF_NODUMP
# Change the flag of the
# specified path using
# os.lchflags() method
os.lchflags(path, flag)
print("Flag changed successfully")
Flag changed successfully