Name: tempdir
Owner: rust-lang-nursery
Description: Temporary directory management for Rust
Created: 2015-03-05 18:16:06.0
Updated: 2018-05-05 14:55:54.0
Pushed: 2018-05-18 16:37:56.0
Homepage: http://doc.rust-lang.org/tempdir
Size: 594
Language: Rust
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
A Rust library for creating a temporary directory and deleting its entire contents when the directory is dropped.
The tempdir
crate is being merged into tempfile
and is available in 3.x
. Please direct new issues and pull requests to tempfile
.
Add this to your Cargo.toml
:
endencies]
dir = "0.3"
and this to your crate root:
rn crate tempdir;
This sample method does the following:
std::io::{self, Write};
std::fs::File;
tempdir::TempDir;
rite_temp_folder_with_files() -> io::Result<()> {
let dir = TempDir::new("my_directory_prefix")?;
let file_path = dir.path().join("foo.txt");
println!("{:?}", file_path);
let mut f = File::create(file_path)?;
f.write_all(b"Hello, world!")?;
f.sync_all()?;
dir.close()?;
Ok(())
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.