M. Phys
M. Phys

Reputation: 147

Get all groups that have access permissions to a folder using Python

On Windows, when you right click on a folder and select 'Properties' and then the 'Security' tab and then click 'Advanced' this shows an Advanced Security settings for the folder, including a 'Permission entries' section, which details group access.

I'm trying to find a way in Python to get all of the information in 'Permission entries', but I'm not sure how I would go about this, or if there's anything in the os library I can use.

Upvotes: 0

Views: 1762

Answers (1)

sarartur
sarartur

Reputation: 1228

You can do it using os with os.system function. The function will write any output to stdout.

import os

path_to_folder = "."
os.system(f'''icacls "{path_to_folder}"''')

If you want to have a call that returns output of the command as a string use:

import subprocess

path_to_folder = "."
output = subprocess.check_output(["icacls", path_to_folder])
print(output)

Keep in mind, obviously icacls is a windows tool, on linux the command would look different (ls -la maybe).

Upvotes: 2

Related Questions