diff options
author | Vincent Breitmoser <look@my.amazin.horse> | 2019-01-17 11:42:49 +0100 |
---|---|---|
committer | Vincent Breitmoser <look@my.amazin.horse> | 2019-01-17 11:42:49 +0100 |
commit | f54c1b81ea64be07e75609bf919729ed4f0cf877 (patch) | |
tree | d274536ed5009d743578db713a1c49b260428263 /src/utils/fileutil.rs | |
parent | 4fcfa895992fb9865e95bb96b751b25348bdf28e (diff) |
add "get" action
Diffstat (limited to 'src/utils/fileutil.rs')
-rw-r--r-- | src/utils/fileutil.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/utils/fileutil.rs b/src/utils/fileutil.rs index 1db5fb8..4f0e6e2 100644 --- a/src/utils/fileutil.rs +++ b/src/utils/fileutil.rs @@ -16,6 +16,17 @@ pub fn file_iter(dir: &Path) -> impl Iterator<Item = PathBuf> { .map(|entry| entry.into_path()) } +pub fn dir_iter(dir: &Path) -> impl Iterator<Item = PathBuf> { + use walkdir::WalkDir; + + let dir = dir.to_path_buf(); + WalkDir::new(&dir).into_iter() + .filter_map(|e| e.ok()) + .filter(|e| e.file_type().is_dir()) + .filter(move |f| f.path() != dir) + .map(|entry| entry.into_path()) +} + pub fn write_file(filepath: &Path, contents: &str) -> io::Result<()> { let mut file = fs::File::create(filepath)?; file.write_all(contents.as_bytes()) |