I want to remove all write permissions from a directory and all it's sub-directories and files with python
I want something like this:
os.chmod(path, "a-w", recursive=True)
In bash it would be this:
chmod -R a-w $path
I want to remove all write permissions from a directory and all it's sub-directories and files with python
I want something like this:
os.chmod(path, "a-w", recursive=True)
In bash it would be this:
chmod -R a-w $path
One way is to use subprocess
module. Your code will look like that:
import subprocess
subprocess.call(['chmod', '-R', 'a-w', path])
For os
-based solution see this answer.
import subprocess
try:
subprocess.check_call(["chmod -R a-w {path}".format(path=path)], shell=True) # Or subprocess.check_call(["chmod", "-R", "a-w", path])
except subprocess.CalledProcessError:
pass # handle errors in the called executable
except OSError:
pass # executable not found