I am busy writing an application that runs under windows
Where is the correct place to save temporary files ?
I am busy writing an application that runs under windows
Where is the correct place to save temporary files ?
\Windows\system32 or \windows\system32\drivers
It's more fun that way.
In the temp directory?
Use GetTempPath or in a batch file %TEMP%
If you are using .NET, please use Path.GetTempPath(). This will guarantee that you use the temporary directory assigned to the user that runs your application, regardless of where it is stored.
If you browse the file system, you will notice that there are many "temp" directories:
... and many more. Some of these paths are OS-dependent, and won't be present on certain windows flavors. So, save yourself some time and hassle, and let the .NET framework figure out where the "temp" path is located.
Use the GetTempPath API, or the equivalent for your programming environment.
C:\Temp is NOT a good choice.
If you are using .Net use code like this:
string baseFolder = System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
string cfgFolder = Path.Combine(baseFolder, "MyAppName");
try
{
if (!Directory.Exists(cfgFolder))
{
Directory.CreateDirectory(cfgFolder);
}
}
catch { } // If no access, not much we can do.
to get a place for medium-term storage of app data, or Path.GetTempPath() for transient storage of data.
Use GetTempPath and and possibly GetTempFileName to determine where to put your temporary files. This is the most reliable, enduser-friendly, and future proof way to get a temporary location for files.
It depends on the language you are using:
string tempFolder = System.IO.Path.GetTempPath();
will return you the appropriate folder in C# for instance.
or, the environment variables TEMP or TMP if you must.