tempfile.gettempdir() result on Windows

Tim Golden tim.golden at viacom-outdoor.co.uk
Fri Jun 3 11:45:42 EDT 2005


| [Leo Breebaart]
| | 
| | On MS Windows, I am trying to find out a good default location to
| | save some temporary files.
| | 
| | The tempfile module seemed to have exactly what I wanted:
| | 
| | >>> import tempfile
| | >>> tempfile.gettempdir()
| | 'c:\\docume~1\\admini~1\\locals~1\\temp'
| | >>>
| | 
| | My problem (entirely cosmetic, but still) is that I also need to
| | show this location to the users of my program, who I suspect
| | would be much happier with a 'proper' Windows path than with this
| | '~1' DOS malarkey.
| | 
| | Does anybody know how I can obtain a temp directory in 'verbose'
| | format (or somehow convert the gettempdir() result to that)?
| 

[Tim Golden]

| Have a look at win32api.GetLongPathName
| (from the pywin32 extensions, in case it wasn't
| obvious). So something like this:
| 
| <code>
| import tempfile
| import win32api
| 
| print tempfile.gettempdir ()
| print win32api.GetLongPathName (tempfile.gettempdir ())
| 
| </code>
| 
| TJG


And, incidentally, while you're there, the win32api.GetTempPath
function does the same as tempfile.gettempdir so you don't
even have to import the tempfile module if you don't want to.

TJG (again)

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________



More information about the Python-list mailing list