Skip to content

Instantly share code, notes, and snippets.

@OMGasm
Last active January 29, 2024 19:20
Show Gist options
  • Save OMGasm/7a172ca31886bfe13932bb7a276ba33f to your computer and use it in GitHub Desktop.
Save OMGasm/7a172ca31886bfe13932bb7a276ba33f to your computer and use it in GitHub Desktop.
use std::{env, io, path::PathBuf};
use walkdir::WalkDir;
fn main() -> io::Result<()> {
let folder = env::args().nth(1).expect("provide song folder");
let (mut charts, mut songs, mut groups, mut fsentries) = (0, 0, 0, 0);
let (mut song_p, mut group_p): (Option<PathBuf>, Option<PathBuf>) = (None, None);
let entries = WalkDir::new(folder)
.min_depth(3)
.max_depth(3)
.into_iter()
.filter_entry(|e| {
fsentries += 1;
if !e.file_type().is_file() {
return false;
}
let path = e.path();
let sm = path.extension().is_some_and(|ext| ext == "sm");
let song = path.parent().unwrap();
let group = song.parent().unwrap();
match (song, song_p.as_mut(), group, group_p.as_mut()) {
(s, Some(sp), _, _) if s == sp => {}
(s, _, g, Some(gp)) if g == gp => {
songs += 1;
song_p = Some(s.to_path_buf())
}
(_, _, g, _) => {
groups += 1;
group_p = Some(g.to_path_buf())
}
}
sm
})
.inspect(|_| charts += 1);
for entry in entries {
let entry = entry?;
let path = entry.path();
println!("{:?}", path);
}
println!("{fsentries} fs entries, {groups} groups, {songs} songs, and {charts} charts");
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment