Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python os.st_uid only return value 0

I'm using windows machine and python 3. I'm trying to get the user id from windows files:

import os
os.stat('filepath').st_uid

However this only returns st_uid = 0 which doesn't make sense.

Can someone please help? If I can't use st_uid, what else I can use to obtain the file user info?

Thanks!


Update: Thanks for the help guys. I end up using windows security API to obtain user information:

Here is the link

like image 682
vivi11130704 Avatar asked Feb 17 '26 04:02

vivi11130704


1 Answers

os.stat() on windows seems very limited: os.stat() on Windows

so id values are zeroed: you cannot use that to get the user id info.

But this Q & A gives most methods to do it in python: Howto determine file owner on windows using python without pywin32

Note: this is a CW answer, as the question isn't really a duplicate of either of the linked answers, but this answer just links both aspects: the issue and the workarounds.

like image 143
Jean-François Fabre Avatar answered Feb 19 '26 18:02

Jean-François Fabre