How to create a temporary file path in Windows XP / Vista

What is the best way to do this? tmpnam () returns the path to a file in the root directory of a drive that requires administrator rights in Windows Vista, so this is not an option.

+3
source share
5 answers

GetTempPath and GetTempFileName should work.

+6
source

The% TEMP% environment variable on Windows points to a directory of temporary user files.

++ Path:: GetTempFileName(), temp ( Path:: GetTempPath()). GetTempFileName() % TEMP% GUID . , . , .

, ,

Martin.

+1

TEMP TMP , ? XP ( Vista), " ", [], [ ].

0

Perhaps you can use the GetTempPath () method of Win32 () in the kernel32.dll file. This is wrapped in .NET using System.IO.Path.GetTempFileName ().

In XP, this returns the path to C: \ Documents and Settings \ username \ Local Settings \ Temp \, so you do not need administrator privileges.

0
source

If you need interoperability, the man page for tmpnam offers:

tmpnam manual page

BUGS
       Never use this function. Use mkstemp(3) instead.

mkstemp man page

SYNOPSIS
       #include <stdlib.h>

       int mkstemp(char *template);

DESCRIPTION
       The mkstemp() function generates a unique temporary file name from template.  The last six characters of template must be
       XXXXXX and these are replaced with a string that makes the filename unique. The file is then created with mode read/write

but all this suggests that you prepared your template with the prefix of the contents of the TMP environment variable.

0
source

Source: https://habr.com/ru/post/1697109/


All Articles