Python Forum
Prevention of deleting and creating folders
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Prevention of deleting and creating folders
#1
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]
Reply
#2
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
Gribouillis likes this post
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  sub-folders in folders from text line jenost 1 2,091 Mar-31-2020, 07:16 AM
Last Post: ndc85430
  Creating multiple folders and other questions coder2be 2 4,009 Aug-19-2018, 06:59 PM
Last Post: coder2be
  Creating folders dynamically with year/month/date sritsv 0 7,155 Oct-16-2017, 03:44 PM
Last Post: sritsv

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020