简体   繁体   中英

How to create undeletable folder in Python?

I'm writing Python code for making a new folder using the os module:

os.makedirs(path)

But this folder can be deleted; I want to make a folder which cannot be deleted. Is it possible to make an undeletable text file?

You can provide access rights when you create the folder

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM