Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::{
- fs::{self, DirEntry},
- io,
- path::Path,
- time::Instant,
- };
- fn main() {
- let dir: Vec<&str> = "directory/path".splitn(2, "/").collect();
- println!("{:?}", dir[0]);
- }
- ///walking a directory only visiting files
- pub fn visit_dirs(dir: &Path, cb: dyn Fn(&DirEntry)) -> io::Result<()> {
- //if path provided leads to a directory
- if dir.is_dir() {
- for entry in fs::read_dir(dir)? {
- let entry = entry?;
- let path = entry.path();
- //for each entry check if it is dir itself
- if path.is_dir() {
- //if so, execute recoursively
- visit_dirs(&path, cb)?;
- } else {
- //do stuff with a file
- cb(&entry);
- }
- }
- }
- Ok(())
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement