Issue
I've got a Python script that is creating a rather lengthy directory structure. Can someone help explain how to successfully 'chmod' several levels back from the directory created? For example, I threw together this small bit of code to test it out. If I run the following code:
log_dir = "/home/milnuts/Public/test1/test2"
if not os.path.exists(log_dir):
os.makedirs(log_dir)
os.chmod(log_dir, 0664)
You can see here that I get the correct permissions set for /test2, but I'd like to set them for /test1 as well. Is there any simple way to do this?
~/Public> ll
total 4 drwxr-s--- 3 milnuts eng 4096 Aug 14 11:15 test1
~/Public> ll test1
total 4 drw-rw-r-- 2 milnuts eng 4096 Aug 14 11:15 test2
Solution
os.makedirs
takes an optional mode
argument that sets the mode of the created directories.
os.makedirs(log_dir, 0o664)
Answered By - user2357112 Answer Checked By - Candace Johnson (WPSolving Volunteer)