Refs #2385 (using a tmp file). In addition, - a better way to get file extensions.