1use std::io::Write;
2use tempfs::{TempDir, TempError};
3
4fn main() -> Result<(), TempError> {
5 let mut temp_dir = TempDir::new_random::<std::path::PathBuf>(None)?;
7
8 {
10 let file = temp_dir.create_file("test1.txt")?;
11 write!(file, "Content for test1")?;
12 }
13
14 {
16 let file = temp_dir.create_random_file()?;
17 write!(file, "Random file content")?;
18 }
19
20 for file_path in temp_dir.list_files() {
22 println!("Managed temp file: {file_path:?}");
23 }
24
25 #[cfg(feature = "regex_support")]
27 {
28 let matching_files = temp_dir.find_files_by_pattern(r"^test\d\.txt$")?;
29 for file in matching_files {
30 if let Some(path) = file.path() {
31 println!("Found file matching regex: {path:?}");
32 }
33 }
34 }
35
36 Ok(())
38}