⚡ Working with temporary directory made easy ☕️
**Temporary Directory ** is a simple class to work with temporary directory for .Net Core developers.
Using the .NET Core command-line interface (CLI) tools:
$ dotnet add package TemporaryDirectory
or with the Package Manager Console:
$ Install-Package TemporaryDirectory
To create a temporary directory at the system temporary directory call the create method:
TemporaryDirectoryHandler directory = new TemporaryDirectoryHandler().Create();
To create a temporary directory with a specific name:
TemporaryDirectoryHandler directory = new TemporaryDirectoryHandler().SetName("MyFolder").Create();
In case the directory already exists you can force create the directory. It will delete the old folder and create the directory againg:
TemporaryDirectoryHandler directory = new TemporaryDirectoryHandler().SetName("MyFolder").SetForce(true).Create();
If you wise to create the folder at another location you can specify this in the constructor:
TemporaryDirectoryHandler directory = new TemporaryDirectoryHandler(location).Create();
You can use the method GetPath to either get the path of the directory or a specific file:
TemporaryDirectoryHandler directory = new TemporaryDirectoryHandler().Create();
string path = directory.GetPath();
TemporaryDirectoryHandler directory = new TemporaryDirectoryHandler().Create();
string path = directory.GetPath("my-file.txt");
You can empty a directory with method Empty:
TemporaryDirectoryHandler directory = new TemporaryDirectoryHandler().Create();
directory.Empty();
You can delete a directory with method Empty:
TemporaryDirectoryHandler directory = new TemporaryDirectoryHandler().Create();
bool result = directory.Delete();
Feel free to contribute with pull requests, bug reports or enhancement suggestions. We love PR's