coven_foundation/files/
tree_copy.rs1use std::path::Path;
5
6pub fn copy_tree(from: &Path, to: &Path) {
9 copy_tree_keeping(from, to, &|_| true);
10}
11
12pub fn copy_tree_keeping(from: &Path, to: &Path, keep: &dyn Fn(&str) -> bool) {
15 std::fs::create_dir_all(to).unwrap();
16 for entry in std::fs::read_dir(from).unwrap() {
17 let entry = entry.unwrap();
18 let name = entry.file_name().into_string().expect("a test file's name is Unicode");
19 let target = to.join(&name);
20 if entry.file_type().unwrap().is_dir() {
21 copy_tree_keeping(&entry.path(), &target, keep);
22 } else if keep(&name) {
23 std::fs::copy(entry.path(), target).unwrap();
24 }
25 }
26}