Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
308 views
in Technique[技术] by (71.8m points)

directory - 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.

question from:https://stackoverflow.com/questions/66051621/get-all-groups-that-have-access-permissions-to-a-folder-using-python

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...