More elegant way to obtain ACLs / permissions for windows directories than using "cacls" dos command?

dananrg at yahoo.com dananrg at yahoo.com
Tue Nov 7 16:00:22 EST 2006


Is there a standard library module in Python 2.4 (Win32) that will
return directory permissions / ACLs (e.g. users, groups, and what
rights they have)?

Otherwise, I'm faced with sending "cacls dirName" commands via os.popen
as below, and then parsing and comparing the text output.

Basically, I'd like to compare what the ACLs a directory should have
against what the actual ACLs are.

Here's what I started with:

import os           # Cross-platform filesystem manipulation

rootDir = "S:\someRootDirectoryHere"

print "*** Printing DIRECTORY names beneath directory " + rootDir + "
***\n"
for dirpath, dirnames, filenames in os.walk(rootDir):
    for dirNm in dirnames:
        theDirPath = os.path.join(dirpath, dirNm)
        print '"' + theDirPath +'"'
        # cacls needs double-quotes around space-containing paths
        result = os.popen("cacls " + '"' + theDirPath + '"')
        # Print the security info (ACLs)for specified directory
        print result.read()

Thanks.




More information about the Python-list mailing list