When dealing with temporary files, especially with more than one, we would like to create our own folder and place them inside. There are several ways to achieve this but for convenience and for completion of the existing Path.GetTempFileName there should be an official API for this.
The API name can be different (CreateTempDirectory?) to avoid confusion between GetTempPath and the meaning of it.
c#
public static partial class Path
{
/// <summary>
/// Creates a uniquely named, empty folder on disk and returns the full path of that directory.
/// </summary>
public static string GetTempDirectory()
}
What format should the directory name have? A guid would be easy, but makes for a long path. For GetTempFileName, Windows since very old days used the tmpXXXX.tmp pattern (and it can run out if they leak) and it looks like for Linux, we emulate that with tmpXXXXXX.tmp
cc: @JeremyKuhne @carlossanlop for insights in this proposal
dotnet/runtime#23538 and dotnet/runtime#23068 track similar requests (there may be others).
IMHO, what we need is a more official, general purpose TempFileCollection that lives in System.IO that allows you to:
FileStream instances (which is more dependable than taking creating your own from a string, and it is also encourages writing more secure code).We _could_ extend TempFileCollection, but it is purpose built for CodeDom and isn't very discoverable. I'm not very keen on pushing that one forward.
Also dotnet/runtime#25173 mentions this.
Closing as we intend to cover this request in dotnet/runtime#2048.
Most helpful comment
dotnet/runtime#23538 and dotnet/runtime#23068 track similar requests (there may be others).
IMHO, what we need is a more official, general purpose
TempFileCollectionthat lives inSystem.IOthat allows you to:FileStreaminstances (which is more dependable than taking creating your own from a string, and it is also encourages writing more secure code).We _could_ extend
TempFileCollection, but it is purpose built for CodeDom and isn't very discoverable. I'm not very keen on pushing that one forward.