refactor: move file explorer logic to it's own module
This commit is contained in:
parent
6e4842a71a
commit
3439bdc37a
2 changed files with 32 additions and 30 deletions
26
src/file_explorer.rs
Normal file
26
src/file_explorer.rs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
use ignore::types::TypesBuilder;
|
||||
use ignore::WalkBuilder;
|
||||
use std::{io, path::PathBuf};
|
||||
|
||||
pub fn walk_dir(path: &PathBuf) -> io::Result<Vec<PathBuf>> {
|
||||
let mut types_builder = TypesBuilder::new();
|
||||
types_builder.add_defaults();
|
||||
|
||||
let accepted_filetypes = ["mp3", "flac"];
|
||||
|
||||
for filetype in accepted_filetypes {
|
||||
let _ = types_builder.add("sound", format!("*.{}", filetype).as_str());
|
||||
}
|
||||
|
||||
types_builder.select("sound");
|
||||
|
||||
let entries: Vec<PathBuf> = WalkBuilder::new(path)
|
||||
.types(types_builder.build().unwrap())
|
||||
.build()
|
||||
.filter_map(|entry| entry.ok())
|
||||
.filter(|entry| !entry.path().is_dir())
|
||||
.map(|entry| entry.path().to_path_buf())
|
||||
.collect();
|
||||
|
||||
Ok(entries)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue