A Rust library for creating a temporary directory and deleting its entire contents when the directory is dropped.
tempdir crate is being merged into
tempfile. Please see this issue to track progress and direct new issues and pull requests to
Add this to your
 = "0.3"
and this to your crate root:
extern crate tempdir;
This sample method does the following:
- Create a temporary directory in the default location with the given prefix.
- Determine a file path in the directory and print it out.
- Create a file inside the temp folder.
- Write to the file and sync it to disk.
- Close the directory, deleting the contents in the process.
use ; use File; use TempDir;
Note: Closing the directory is actually optional, as it would be done on drop. The benefit of closing here is that it allows possible errors to be handled.