【问题标题】:How to create undeletable folder in Python?如何在 Python 中创建不可删除的文件夹?
【发布时间】:2021-05-22 17:48:54
【问题描述】:

我正在编写 Python 代码以使用 os 模块创建一个新文件夹:

os.makedirs(path)

但是这个文件夹可以删除;我想做一个不能删除的文件夹。是否可以制作不可删除的文本文件?

【问题讨论】:

标签: python


【解决方案1】:

您可以在创建文件夹时提供访问权限

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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-23
    • 2021-05-26
    • 2010-12-21
    • 2023-01-16
    • 1970-01-01
    相关资源
    最近更新 更多