This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: os.utime does not work on directories under Windows
Type: Stage:
Components: Documentation Versions: Python 2.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: tim.peters Nosy List: alexanderweb, boyleboyle, endavis, tim.peters
Priority: normal Keywords:

Created on 2004-11-04 13:46 by boyleboyle, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (11)
msg22998 - (view) Author: Boyle (boyleboyle) Date: 2004-11-04 13:46
On windows 2000, os.utime does not work on a directory,
but gives a permission denied error.

OSError: [Errno 13] Permission denied: '<PATH>'

msg22999 - (view) Author: endavis (endavis) Date: 2004-11-04 16:07
Logged In: YES 
user_id=1131103

I also get the Permission Denied on Windows XP for directories.

Windows XP SP2
Python 2.3.4
pywin32 build 202 
NTFS file system
msg23000 - (view) Author: endavis (endavis) Date: 2004-11-04 16:13
Logged In: YES 
user_id=1131103

Another note to add:

This is only with unicode file names.
msg23001 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2004-11-04 21:05
Logged In: YES 
user_id=31435

The Python docs say utime() sets times on files.  On 
Windows, directories aren't files; on Unix, directories are 
files.  You'll get the same error on Windows if you pass a 
directory path to Microsoft's _utime() function from C code.

See the MS docs for details, esp. the docs for the EACCES 
error:

http://msdn.microsoft.com/library/en-us/ 
vclib/html/_crt__utime.2c_._wutime.asp
msg23002 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2004-11-04 21:36
Logged In: YES 
user_id=31435

I checked in changes to the utime() docs, for Python 2.4, 
being explicit about the case of paths that name directories.  
Changed the Category of this report to Documentation, and 
am closing it now.  If you want utime() to work on directories 
under Windows, you'll have to convince Microsoft to 
implement that in their C library's _utime() function.
msg23003 - (view) Author: Alexander Schremmer (alexanderweb) Date: 2004-11-05 21:10
Logged In: YES 
user_id=254738

The docs say about the return codes of _utime:
 EACCES (sic)
 Path specifies directory or read-only file

So it is expected behavior (but not posix compatible, I guess).

Workaround: use cygwin's python.
msg23004 - (view) Author: Boyle (boyleboyle) Date: 2004-11-08 13:48
Logged In: YES 
user_id=982057

I understand it is documented and one of the many quirks of
windows, however it would we nice if Python would just work
around this problem.

I was converting my Perl scripts to Python scripts (which
look a lot nicer and more readable), when I ran into this
utime problem. The windows perl implementation had no
problem with utime on a directory. This is because they
catch the EACCES error and work around the problem (see
implementation in win32/win32.c in
http://www.perl.com/CPAN/src/stable.tar.gz)

Any chance something like this will be done for Python?
msg23005 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2004-11-08 15:34
Logged In: YES 
user_id=31435

> Any chance something like this will be done for Python?

Sure -- it's equal to the chance that someone who cares 
about this cares enough to contribute a patch (code, docs, 
tests).
msg23006 - (view) Author: Alexander Schremmer (alexanderweb) Date: 2004-11-09 22:55
Logged In: YES 
user_id=254738

I extracted the relevant code piece from Perl's sources. You
can find it here:
http://moinmoin.wikiwikiweb.de/AlexanderSchremmer/copystat?action=AttachFile&do=get&target=perl_utime.c

Somebody with experience in hacking Python should be able to
adopt it to the Python's API.
msg23007 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2004-11-10 01:26
Logged In: YES 
user_id=31435

alexanderweb:  It isn't a question of difficulty, it's a question 
of someone volunteering to do the all the work.  It definitely 
does not help to extract GPL'ed code from some other 
project -- I'm not even going to look at it, lest it open the 
PSF to lawsuits later (Python doesn't use the GPL), and I 
strongly discourage anyone who *might* want to take this 
on from looking at it either.

Someone who knows enough about the Win32 API to do this 
job at all for Python won't have trouble doing a "clean room" 
implementation.  It needs someone who both cares enough 
and can make that time.  There is no technical problem in 
doing it.
msg23008 - (view) Author: Alexander Schremmer (alexanderweb) Date: 2004-11-10 07:49
Logged In: YES 
user_id=254738

The licensing issue is not really a problem:
    Release         Derived     Year        Owner       GPL-
		    from                                compatible? (1)
    2.0.1           2.0+1.6.1   2001        PSF         yes
    2.1.1           2.1+2.0.1   2001        PSF         yes
    2.2             2.1.1       2001        PSF         yes
    2.1.2           2.1.1       2002        PSF         yes
    2.1.3           2.1.2       2002        PSF         yes
    2.2.1           2.2         2002        PSF         yes
    2.2.2           2.2.1       2002        PSF         yes
    2.3             2.2.2       2002-2003   PSF         yes
    2.3.1           2.3         2002-2003   PSF         yes
    2.3.2           2.3.1       2002-2003   PSF         yes

Footnotes:

(1) GPL-compatible doesn't mean that we're distributing
Python under
    the GPL.  All Python licenses, unlike the GPL, let you
distribute
    a modified version without making your changes open
source.  The
    GPL-compatible licenses make it possible to combine
Python with
    other software that is released under the GPL; the
others don't.
History
Date User Action Args
2022-04-11 14:56:07adminsetgithub: 41122
2004-11-04 13:46:13boyleboylecreate