44 lines
1.0 KiB
Rust
44 lines
1.0 KiB
Rust
use std::path::PathBuf;
|
|
|
|
fn main() {
|
|
const MUSIC_EXTENSIONS: [&str; 14] = [
|
|
"flac",
|
|
"mp3",
|
|
"ogg",
|
|
"wav",
|
|
"m4a",
|
|
"alac",
|
|
"opus",
|
|
"webm",
|
|
"wma",
|
|
"aiff",
|
|
"s3m",
|
|
"mod",
|
|
"it",
|
|
"xm"
|
|
];
|
|
match home::home_dir() {
|
|
Some(home) => {
|
|
let music_dir = get_music_dir(&home);
|
|
let glob_walker = globwalk::GlobWalkerBuilder::from_patterns(&music_dir, &[format!("*.{{{}}}", MUSIC_EXTENSIONS.join(","))])
|
|
.follow_links(true)
|
|
.build()
|
|
.unwrap()
|
|
.into_iter()
|
|
.filter_map(Result::ok);
|
|
for file in glob_walker {
|
|
println!("{}", file.path().to_string_lossy());
|
|
}
|
|
}
|
|
None => {
|
|
panic!("Unable to get your home directory.")
|
|
}
|
|
}
|
|
}
|
|
|
|
fn get_music_dir(path: &PathBuf) -> PathBuf {
|
|
let mut music_dir = path.clone();
|
|
music_dir.push("Music");
|
|
return music_dir;
|
|
}
|