in reply to tempdir with template fails

As imp mentioned, this is behavior is documented. Unfortunately, the source code follows the docs. :-) I was hoping tempdir accepted a SUFFIX parameter just as tempfile does, but it does not (as of version 0.16).

If you really want your temp dir to have an extension, you could still use File::Temp but it would require a bit more work.

  1. Find all existing dirs in your base dir and create a file for them. For example, if the dir was named 'dir1234.mbox' you could create a file with the name 'temp_dir1234.mbox'.
  2. Use tempfile to create a new (unique) temp file in the base dir using the template 'temp_XXXXXXX' and SUFFIX 'mbox'.
  3. Since the existing directory names match the file names, you can create a directory named 'temp_XXXXXXX.mbox' (for whatever XXXXXXX is) and know it is unique. (If you were worried about race conditions you could check to see if it existed first.)
  4. When you're done with the temp dir and it is deleted, make sure you delete the corresponding file as well.

I'll be the first to say that the solution enumerated above is an ugly hack. If it were me, I'd use extensionless directory names or just check to see if it existed before I tried to create it. Do you really need the power of File::Temp for this? If you're not creating multiple temp dirs simultaneously this approach seems like overkill.