quick equivalent of 'touch' command?

Clarence Gardner clarence at netlojix.com
Sun Oct 29 20:48:57 EST 2000


On Sat, 28 Oct 2000, Olivier Dagenais wrote:
>Open the file for output/update and close it right after.  You may need to
>use the low-level os.open with a few flags.
>
>Or maybe you can just set the file's time/date?  I'd look in the os module
>for stuff like this..

I believe the original poster was working on Windows(TM), so this
isn't strictly relevant, but for general knowledge I'll mention that on
unix, the open() mentioned above will not work, and changing the time
requires superuser privilege.  To touch the file using file methods, you'll
have to actually write to it.  E.g., read the first byte from the file and then
write it back (which won't work with a zero-length file), or seek to the end,
write a byte, then back up one byte and truncate at the file position.



More information about the Python-list mailing list