【发布时间】:2021-05-22 17:48:54
【问题描述】:
我正在编写 Python 代码以使用 os 模块创建一个新文件夹:
os.makedirs(path)
但是这个文件夹可以删除;我想做一个不能删除的文件夹。是否可以制作不可删除的文本文件?
【问题讨论】:
标签: python
我正在编写 Python 代码以使用 os 模块创建一个新文件夹:
os.makedirs(path)
但是这个文件夹可以删除;我想做一个不能删除的文件夹。是否可以制作不可删除的文本文件?
【问题讨论】:
标签: python
您可以在创建文件夹时提供访问权限
import os
# define the name of the directory to be created
path = "/tmp/year"
# define the access rights (readable and accessible by all users, and write access by only the owner)
access_rights = 0o755
try:
os.mkdir(path, access_rights)
except OSError:
print ("Creation of the directory %s failed" % path)
else:
print ("Successfully created the directory %s" % path)
【讨论】: