0

I need to get the file owner but I don't see a simple way to achieve it.

I tried this but didn't work. Same with this, not working in Windows.

I used os.path for other file info, but doesn's seem to have anythin related to file owners.

Any hint?

martineau
  • 119,623
  • 25
  • 170
  • 301
Nira
  • 197
  • 1
  • 1
  • 12

2 Answers2

1

I found the solution in this url.

from win32 import win32security
OwnrSecInfo = win32security.GetFileSecurity(inFilePath,
win32security.OWNER_SECURITY_INFORMATION)
SecDscp = OwnrSecInfo.GetSecurityDescriptorOwner()
# returns a tuple (u'owner, u'domain)
ownr = win32security.LookupAccountSid(None,SecDscp)
return str(ownr[0])
Nira
  • 197
  • 1
  • 1
  • 12
0

This post seems like what you are asking. Could you first check the solution provided there.

As post owner mentions above, post is a solution for UNIX-based systems. It uses the pwd module of python, which is not supported for Windows.

Here is an alternative for Windows. I hope that helps.

Nubok
  • 3,502
  • 7
  • 27
  • 47
Meto
  • 638
  • 7
  • 18
  • I tried that too, but it seems that pwd is for Linux and doesn't work in Windows. – Nira Mar 06 '20 at 08:56
  • 3
    Don't post (parts of) another answer as an answer. Try marking the question as duplicate instead. – CristiFati Mar 06 '20 at 08:57
  • @CristiFati I'm a big believer in doing things yourself rather than asking someone else to do it. – Jean-François Corbett Mar 06 '20 at 09:25
  • @Jean-FrançoisCorbett: True, but I wouldn't mark the question as a duplicate, at least not without some additional info (and now I have the required reputation to close the question instead of just marking it and waiting for other users to do the same). Also some of the "unwritten rules" or practices are not so obvious, especially for new users, so they need to get it from somewhere. – CristiFati Mar 06 '20 at 09:38