#temp-dir #directory #temporary #file #path

maketemp

Create temporary directory and files

1 unstable release

0.1.0 Mar 21, 2022

#1388 in Filesystem

MIT license

27KB
481 lines

Create temporary directory and file.

  • No dependencies.
  • Create in any directory.
  • Add prefix and suffix in the name.
  • Auto deletion.
use maketemp::TempDir;
use std::path::Path;

fn main() {
    let p;
    
    {
        // create temporary directory.
        let dir = TempDir::open();
        p = dir.path().to_string();
        
        // true.
        println!("path {} exists: {} ",&p,Path::new(&p).exists());
        
        // delete `dir` automatically here.
    }
    
    // false.
    println!("path: {} exists: {}",&p,Path::new(&p).exists());
}

No runtime deps