Starting with Windows 10, Storage Sense has allowed users to specify %TEMP%
folder cleanup that are as frequent as once a day. Technically it can run even more often is set to activate on low disk space, depending on one's disk usage patterns.
In light of that, what is the point of the %TEMP%
folder? How would I ever use a folder where every file I put there can technically be removed by the system the moment after I finish writing it?
Here is a real world scenario where this hit me (code simplified for brevity):
var ffmpegPath = Path.Combine(Path.GetTempPath(), "ffmpeg");
DownloadFfmpeg(path: ffmpegPath);
foreach (var videoFile in videoFiles) { //suppose there are dozens of files to process
DoSomeHeavyProcessing(ffmpegPath); //suppose each file takes an hour to process
}
This worked great for the first few hours, but then at some arbitrary point in time the downloaded ffmpeg
folder was deleted and all the subsequent files could not be processed. In fact, if I understand correctly, in theory even code like this could fail:
var path = Path.Combine(Path.GetTempPath(), "foo");
File.WriteAllText(path, "bar");
Console.WriteLine(File.ReadAllText(path));
Now, I know how to solve this - simply use %APPDATA%
, %LOCALAPPDATA%
or %PROGRAMDATA%
. But that's the point - since the advent of Storage Sense, why would I ever use %TEMP%
rather than the former folders?
LocalCacheFolder
. See docs and stackoverflow.com/a/23461912 – Recognize