Created
October 16, 2018 17:10
-
-
Save adamchalmers/59cd1b8ace4828281805064d61c7f66c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::ffi::OsStr; | |
use std::io; | |
use std::fs::{self}; | |
use std::path::{Path, PathBuf}; | |
// Find all files in the given directory with the given extension | |
fn paths_matching(extension: &str, dir: &Path) -> io::Result<Vec<PathBuf>> { | |
let mut paths: Vec<PathBuf> = Vec::new(); | |
for entry in fs::read_dir(dir)? { | |
let entry = entry?; | |
let path = entry.path(); | |
if path.extension() == Some(OsStr::new(extension)) { | |
paths.push(path); | |
} | |
} | |
Ok(paths) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment