file permissions on windows XP (home)

Duncan Booth duncan.booth at invalid.invalid
Wed Jun 8 04:31:34 EDT 2005


barney wrote:

> I realise that theses are windows rather than python issues but I would
> expect there would be some reliable way of changing the file
> permissions from within python. I'm updating ID3 tags in MP3 file to
> give some context. If I use something like winamp to make the change to
> the ID3 tag then the file is updated with no permission errors so there
> must be a way....
> 
So it looks as though you have been using cygwin to set the file's access 
permissions and cygwin uses a complex mapping of unix's permission bits 
onto file security, whereas Python uses the more common, but incomplete 
mapping as implemented by the C runtime library.

The relationship between commands is that Python's chmod is equivalent to 
using the command line ATTRIB command, but Cygwin's chmod is equivalent to 
using both ATTRIB and CACLS.

I can think of three options open to you:

a) Let cygwin fix what cygwin broke:

   os.system('\\cygwin\\bin\\chmod u+rwx ' + filename)

b) Use cacls to fix it:

   os.system('cacls %s /P %s:F' % (filename, username))

c) Use win32security.SetFileSecurity()

See http://mail.python.org/pipermail/python-win32/2004-July/002111.html for 
a thread on using this api.




More information about the Python-list mailing list