Datei Ersteller auslesen?
Verfasst: Donnerstag 23. Dezember 2021, 20:23
Ich möchte ein Programm schreiben, welches mir Anzeigt welcher Nutzer Daten in einer Ordnerstruktur abgelegt hat.
Ist das möglich?
Ist das möglich?
Seit 2002 Diskussionen rund um die Programmiersprache Python
https://www.python-forum.de/
Code: Alles auswählen
import pathlib
import platform
if platform.system() == "Windows":
from win32api import GetUserNameEx
from win32con import NameSamCompatible
from win32security import OWNER_SECURITY_INFORMATION, GetFileSecurity, LookupAccountSid
# def whoami() -> str:
# return GetUserNameEx(NameSamCompatible).rpartition("\\")[2].strip()
def get_owner(file: str | pathlib.Path) -> tuple[str, str]:
"""
Return owner and domain of current file.
"""
file = str(file)
owner_sid = GetFileSecurity(
file,
OWNER_SECURITY_INFORMATION,
).GetSecurityDescriptorOwner()
name, domain, _ = LookupAccountSid(None, owner_sid)
return name, domain
class WindowsPath(pathlib.WindowsPath):
def owner(self):
return get_owner(self)[0]
def Path(*args, **kwargs):
path = pathlib.Path(*args, **kwargs)
if isinstance(path, pathlib.WindowsPath):
return WindowsPath(path)
return p
else:
Path = pathlib.Path
Code: Alles auswählen
#var für die DM liste
DMList = open('textdatei.txt', 'r')
for zeile in DMList:
#username list
usernames = ['DMList']