Search code examples
pythontemporary-files

Why is tempfile using DOS 8.3 directory names on my XP box?


>>> import tempfile
>>> tempfile.mkstemp()
(3, 'c:\\docume~1\\k0811260\\locals~1\\temp\\tmpk6tpd3')

It works, but looks a bit strange. and the actual temporary file name is more than 8 letters.

Why doesn't it use long file names instead?


Solution

  • mkstemp uses the environment variables TMPDIR, TEMP or TMP (the first one that is set) to determine where to put your temporary file. One of these is probably set to c:\docume~1\k0811260\locals~1\temp on your system. Issue

    echo %%tmp%%
    

    etc. in a command window ("DOS box") to find out for sure.

    Which, in fact, is a good thing because some naïve modules/programs (e.g., those that call external OS commands) may get confused when a directory name contains a space, due to quoting issues.