0

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?

ad absurdum
  • 19,498
  • 5
  • 37
  • 60

1 Answers1

4

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)
Vik
  • 59
  • 7