Skip to content

Instantly share code, notes, and snippets.

@gabriel-lopez
Created March 29, 2020 12:43
Show Gist options
  • Select an option

  • Save gabriel-lopez/c073d04727e867b35a01a8abe6b07c53 to your computer and use it in GitHub Desktop.

Select an option

Save gabriel-lopez/c073d04727e867b35a01a8abe6b07c53 to your computer and use it in GitHub Desktop.
Utility class used to get a temporary folder path.
public sealed class TempFolder
{
public string Path { get; }
public TempFolder()
{
string guid = Guid.NewGuid().ToString();
string tempPath = System.IO.Path.GetTempPath();
string path = System.IO.Path.Combine(tempPath, guid);
// ensure that the directory doesn't already exists
while (Directory.Exists(path))
{
guid = Guid.NewGuid().ToString();
path = System.IO.Path.Combine(tempPath, guid);
}
Path = Directory.CreateDirectory(path).FullName;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment