Peter Hansen wrote: >> >> Why is python returing True from os.access? >> Why isn't chmod doing anything? > > Check your results using os.stat() after doing that, perhaps? If it > shows the right values for the permissions, then clearly the problem has > nothing to do with Python per se, or your own code. >
And also remember that in windows the mode in os.chmod and os.stat is only loosely related to the actual permissions on the file. In particular there is a 'readonly' flag which is separate from whether any particular user or group has write access. The only way to tell whether you have access to a file in windows really is to try to open it and handle the exception. Try using the properties panel, or the windows CACLS to display the security permissions on the file. If you start with a plain file, then you and administrators probably have full access (CACLS will display 'your username:F'). If you use Python to set an access mode, it simply tries to toggle the attributes on the file itself. If you use Cygwin's chmod it will mess about with the security permissions in an attempt to get as close to the Unix file mode as it can, so your nice simple 'F' mode might become something truly horrendous: Before: C:\temp>cacls testfile.txt C:\temp\testfile.txt BUILTIN\Administrators:F NT AUTHORITY\SYSTEM:F DELL5150\Duncan:F BUILTIN\Users:R C:\temp>\cygwin\bin\chmod 744 testfile.txt C:\temp>cacls testfile.txt C:\temp\testfile.txt DELL5150\Duncan:(special access:) STANDARD_RIGHTS_ALL DELETE READ_CONTROL WRITE_DAC WRITE_OWNER SYNCHRONIZE STANDARD_RIGHTS_REQUIRED FILE_GENERIC_READ FILE_GENERIC_WRITE FILE_GENERIC_EXECUTE FILE_READ_DATA FILE_WRITE_DATA FILE_APPEND_DATA FILE_READ_EA FILE_WRITE_EA FILE_EXECUTE FILE_READ_ATTRIBUTES FILE_WRITE_ATTRIBUTES DELL5150\None:(special access:) READ_CONTROL SYNCHRONIZE FILE_GENERIC_READ FILE_READ_DATA FILE_READ_EA FILE_READ_ATTRIBUTES Everyone:(special access:) READ_CONTROL SYNCHRONIZE FILE_GENERIC_READ FILE_READ_DATA FILE_READ_EA FILE_READ_ATTRIBUTES BUILTIN\Administrators:F NT AUTHORITY\SYSTEM:F BUILTIN\Users:R -- http://mail.python.org/mailman/listinfo/python-list