Find the file owner

You can find the owner of a file by running the following command. The command will return the owner of the file and the domain

import win32api
import win32con
import win32security

def owner(file):
    sd = win32security.GetFileSecurity (file, win32security.OWNER_SECURITY_INFORMATION)
    owner_sid = sd.GetSecurityDescriptorOwner ()
    name, domain, type = win32security.LookupAccountSid(None, owner_sid)
    return (name,domain)

filename = "my.file"

print(f"The owner of the file {filename} is {owner(filename)[0]}")
The owner of the file my.file is my.user