473,408 Members | 2,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Windows: get owner and group of a file

Hello,

with ls -l on windows I get
-rw-r--r-- 1 500 everyone 320 Nov 09 09:35 myfile

How can I get on windows with a standard python 2.2 (without windows
extensions) the information "500" and "everyone" (owner and group)?
Also I cannot use popen('ls -l').

With
import stat
stat_info = os.lstat(myfile)
owner = "%-8s" % stat_info.st_uid
group = "%-8s" % stat_info.st_gid
I get 0 for owner and group.

Thanks for your hints, Kai

Dec 6 '06 #1
6 6752
kai rosenthal wrote:
Hello,

with ls -l on windows I get
-rw-r--r-- 1 500 everyone 320 Nov 09 09:35 myfile

How can I get on windows with a standard python 2.2 (without windows
extensions) the information "500" and "everyone" (owner and group)?
Also I cannot use popen('ls -l').
Are you by any chance running cygwin? That comes with ls, but windows
doesn't. So you need to add the appropriate cygwin binary dirs to you path.
But you probably won't want that anyway, as thus your code would only run
on a machine with cygwin installed.
With
import stat
stat_info = os.lstat(myfile)
owner = "%-8s" % stat_info.st_uid
group = "%-8s" % stat_info.st_gid
I get 0 for owner and group.
I'm not sure if stat-calls are fully supported on windows - the windows
rights management is considerably different from unixish ones.

From the docs:

"""
For backward compatibility, the return value of stat() is also accessible as
a tuple of at least 10 integers giving the most important (and portable)
members of the stat structure, in the order st_mode, st_ino, st_dev,
st_nlink, st_uid, st_gid, st_size, st_atime, st_mtime, st_ctime. More items
may be added at the end by some implementations. The standard module stat
defines functions and constants that are useful for extracting information
from a stat structure. (On Windows, some items are filled with dummy
values.)
"""

Note the last sentence. You should try and look what win32 has to offer.

Diez
Dec 6 '06 #2
Tim Golden wrote:
Wow. Python 2.2. No extensions. Not even popen (). You don't
want much, do you? I *think* the answer is that you can't.
does the "group" concept even exist on Windows ? cannot recall I've
ever seen "ls -l" print anything but "everyone"...

</F>

Dec 6 '06 #3
>with ls -l on windows I get
>-rw-r--r-- 1 500 everyone 320 Nov 09 09:35 myfile

Are you by any chance running cygwin? That comes with ls, but
windows doesn't.
Another alternative might be mounting their Windows-formatted
drive from within a *nix-like OS. These permissions are usually
set via the /etc/fstab mounting options for the drive. I don't
remember what the defaults are, as I have mine set up to take a
forced set of uid/gid for users/groups specific to my system.
Because at least FAT32 doesn't have this idea of groups (mapping
to NTFS is an entirely different ball of wax), you can specify a
default mask for everything or specify the directory mask
separately from the file mask.

man mount

will give more details on such goods.

-tkc

Dec 6 '06 #4
Fredrik Lundh <fr*****@pythonware.comwrote:
Tim Golden wrote:
>Wow. Python 2.2. No extensions. Not even popen (). You don't
want much, do you? I *think* the answer is that you can't.

does the "group" concept even exist on Windows ? cannot recall I've
ever seen "ls -l" print anything but "everyone"...
Domain users have a 'primary group'. Actually, contrary to what I said in
the previous post I'm not sure that files have the concept. It may just be
users and the actual group permissions then get stored on the file. If so
and if you assigned any other groups permission on the file you may not be
able to distinguish which is the original group for the file and which was
added later.
Dec 6 '06 #5
"kai rosenthal" <ka**********@tiscali.dewrote:
Hello,

with ls -l on windows I get
-rw-r--r-- 1 500 everyone 320 Nov 09 09:35 myfile

How can I get on windows with a standard python 2.2 (without windows
extensions) the information "500" and "everyone" (owner and group)?
Also I cannot use popen('ls -l').

With
import stat
stat_info = os.lstat(myfile)
owner = "%-8s" % stat_info.st_uid
group = "%-8s" % stat_info.st_gid
I get 0 for owner and group.

Thanks for your hints, Kai
You can get the owner by doing os.popen('dir /q') and parsing the output,
but it is a string not a number (which I guess is why stat/lstat can't
return a value). Internally the ownber and primary group are stored as
security identifier (SID) values: a SID is a variable length structure.

Running the CACLS command on a file will give you the full permission
settings for that file. They are a lot more complex than the simple rwx
settings from unix. e.g.

C:\temp>cacls t.py
C:\temp\t.py BUILTIN\Administrators:F
NT AUTHORITY\SYSTEM:F
MYPC\Duncan:F
BUILTIN\Users:R
C:\temp>cacls .
C:\temp BUILTIN\Administrators:F
BUILTIN\Administrators:(OI)(CI)(IO)F
NT AUTHORITY\SYSTEM:F
NT AUTHORITY\SYSTEM:(OI)(CI)(IO)F
MYPC\Duncan:F
CREATOR OWNER:(OI)(CI)(IO)F
BUILTIN\Users:R
BUILTIN\Users:(OI)(CI)(IO)(special access:)
GENERIC_READ
GENERIC_EXECUTE

BUILTIN\Users:(CI)(special access:)
FILE_APPEND_DATA

BUILTIN\Users:(CI)(special access:)
FILE_WRITE_DATA

So far as I know, to get the primary group for a file you will need to call
the win32 function GetSecurityInfo asking for the
GROUP_SECURITY_INFORMATION. This will give you an appropriate security
descriptor. See http://msdn2.microsoft.com/en-us/library/aa379561.aspx

Dec 6 '06 #6

kai rosenthal wrote:
Hello,

with ls -l on windows I get
-rw-r--r-- 1 500 everyone 320 Nov 09 09:35 myfile

How can I get on windows with a standard python 2.2 (without windows
extensions) the information "500" and "everyone" (owner and group)?
Also I cannot use popen('ls -l').

With
import stat
stat_info = os.lstat(myfile)
owner = "%-8s" % stat_info.st_uid
group = "%-8s" % stat_info.st_gid
I get 0 for owner and group.

Thanks for your hints, Kai
If you can't use os.popen('ls -l'), can you instead use os.system('ls
-l >C:\\Temp\\result.txt') and then parse result.txt?

Dec 7 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: black hawk | last post by:
Hello, i have a big problems, to install oracle 9i v9.2 Server to my "Windows XP" with Service Pack 2 and all security and other updates from Microsoft. The "Universall Installer" (Standard...
0
by: black hawk | last post by:
Hello, i have a big problems, to install oracle 9i v9.2 Server to my "Windows XP" with Service Pack 2 and all security and other updates from Microsoft. The "Universall Installer" (Standard...
0
by: Tim Haughton | last post by:
I've just released an article on using Test Driven Development with C# and Windows Forms. GUI's are often difficult to test, so I thought it might be of interest. The article along with the...
1
by: Ange T | last post by:
Hi, I have a secured Access 2000 database, and have encountered a strange error that I can't find any similar postings on. I'd really appreciate your help! In my database, I have a number of...
1
by: Brian | last post by:
I have a complex problem that needs a lot of background explanation before I can ask questions, so here goes.... Our system consists of two servers. -WebUI server - Windows 2000 - runs asp.net...
4
by: Kristof Despiere | last post by:
Suppose you have one domain, filled with a couple of users. What needs to be done now is I need to start a windows application from a webform by pressing a button on the webform (for example). ...
1
by: Carlos | last post by:
I use the below codes downloaded from http://www.visualbasicforum.com/showthread.php?t=158264 to perform a recursive search of files and folders. I can obtain most of the information such as the...
3
by: datastreamcowboy | last post by:
Here's the deal I'm relatively new to C# and i got this windows form that i would like to use to edit the data in an XML file. I can use XMLRead and make a tree view that works.. but how do I get...
3
by: aagarwal8 | last post by:
Hi, I have a main form, which i use to open secondary forms. From the secondary form i need to open a Modal Window in such a way that, my secondary form is blocked, but i can still access my...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.