HELP: Python equivalent of UNIX command "touch"

Roy Smith roy at
Wed Mar 2 17:17:52 CET 2005

In article <4225E4E9.5070903 at>,
pekka niiranen  <pekka.niiranen at> wrote:
>Roy Smith wrote:
>> pekka niiranen  <pekka.niiranen at> wrote:
>>>Does anybody know Python recipe for changing the date
>>>of the directory or files in W2K to current date and time?
>>>In UNIX shell command "touch" does it.
>> You want os.utime()
>Nope, it does not work for directories in Windows

Well, there's always the old fashioned way (which early versions of
touch used).  Read the first byte of the file, rewind, write the byte
back out, seek to the end (to preserve the file length), and close the
file.  I'm not sure what to do for directories (I guess you could
create and delete a temp file).

Of course, if you told me that doesn't work on Windows either, I
wouldn't be too surprised. :-)

More information about the Python-list mailing list