#fs-file #fs #file #directory #temporary #deleting

unmaintained tempdir

A library for managing a temporary directory and deleting all contents when it's dropped

11 releases

Uses old Rust 2015

0.3.7 Mar 21, 2018
0.3.6 Jan 30, 2018
0.3.5 Aug 1, 2016
0.3.4 Apr 2, 2015
0.1.0 Feb 22, 2015

#6 in #deleting

Download history 105265/week @ 2024-01-17 82324/week @ 2024-01-24 85044/week @ 2024-01-31 92355/week @ 2024-02-07 86006/week @ 2024-02-14 103564/week @ 2024-02-21 104358/week @ 2024-02-28 99452/week @ 2024-03-06 95571/week @ 2024-03-13 98366/week @ 2024-03-20 113200/week @ 2024-03-27 120533/week @ 2024-04-03 117246/week @ 2024-04-10 120637/week @ 2024-04-17 124088/week @ 2024-04-24 89626/week @ 2024-05-01

472,143 downloads per month
Used in fewer than 761 crates

MIT/Apache

17KB
79 lines

tempdir

A Rust library for creating a temporary directory and deleting its entire contents when the directory is dropped.

Build Status Build status

Documentation

Deprecation Note

The tempdir crate is being merged into tempfile. Please see this issue to track progress and direct new issues and pull requests to tempfile.

Usage

Add this to your Cargo.toml:

[dependencies]
tempdir = "0.3"

and this to your crate root:

extern crate tempdir;

Example

This sample method does the following:

  1. Create a temporary directory in the default location with the given prefix.
  2. Determine a file path in the directory and print it out.
  3. Create a file inside the temp folder.
  4. Write to the file and sync it to disk.
  5. Close the directory, deleting the contents in the process.
use std::io::{self, Write};
use std::fs::File;
use tempdir::TempDir;

fn write_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.

Dependencies

~350–530KB