Python Forum

Full Version: Prevention of deleting and creating folders
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi. I was wondering if anyone has any idea how to prevent Windows user to delete and create folders / files in a specific path and its sub-folders.

I'm using a python script to create a specific folder structure (based on Git-Repositories).

The aim is to keep users from altering this structure. They are allowed to create and delete folders / files on the "lowest" levels of this folder structure (so they can work within this framework).

I've already tried setting a command using the subprocess library:

cmd = f'icacls "{D:\Git}" /deny Everyone:(WD,AD) /T /C /L /Q'
subprocess.run(cmd, shell=True)
But this doesn't seem to do anything. When I try to execute the command in a cmd-window I just get an error message that 0 Files haven been changed and one error occured.

I create the folders iterative. So I could use a specific command for each and every folder - should something like this exist.

Any help would be very appreciated!

[Image: Uf226vx.png]
The Operating System and File System manages Access Rights to directories and files. On Windows, it's called ACL. Doing this on Linux is easier, because you have lesser settings.

I found some info here: https://windowsforum.com/threads/python-...ost-894609

Here is a gist which shows the use of win32security (from pywin32): https://gist.github.com/cbwar/fee1bfbe0e...0eeae36bd3
The use of os.chmod is useless on Windows. Windows just ignores this setting, but the ACL flags aren't ignored.

Python-Wiki: https://wiki.python.org/moin/HelpOnAccessControlLists