Skip to content

Instantly share code, notes, and snippets.

@adamchalmers
Created October 16, 2018 17:10
Show Gist options
  • Save adamchalmers/59cd1b8ace4828281805064d61c7f66c to your computer and use it in GitHub Desktop.
Save adamchalmers/59cd1b8ace4828281805064d61c7f66c to your computer and use it in GitHub Desktop.
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