feat: Added file scanning

Created a sub module for file system oprations

Create proof of concept function to recursivly scan directories for files
This commit is contained in:
Nickiel12 2022-12-10 22:05:40 -08:00
parent 2dfd4aef4f
commit 4b1b6e7648
2 changed files with 41 additions and 15 deletions

38
src/file_operations.rs Normal file
View file

@ -0,0 +1,38 @@
use std::path::PathBuf;
use scan_dir::ScanDir;
const SUPPORTED_FILETYPES: [&str; 1] = ["mp3"];
pub fn scan_music_dir(root: String) -> Result<(), ()> {
let mut directories = Vec::<PathBuf>::new();
directories.push(root.into());
while directories.len() != 0 {
let target = match directories.pop() {
Some(val) => val,
None => {
panic!("Whoa man this ai't right");
}
};
ScanDir::dirs()
.read(target.clone(), |iter| {
for (entry, name) in iter {
directories.push(entry.path());
println!("I found a director {:?} at path {:?}", name, entry.path());
}
})
.unwrap();
ScanDir::files()
.read(target, |iter| {
for (entry, name) in iter {
println!("found file {:?} at path {:?}", name, entry.path());
}
})
.unwrap();
}
Ok(())
}

View file

@ -2,6 +2,8 @@ use clap::Parser;
use dirs_next;
use scan_dir::ScanDir;
pub mod file_operations;
#[derive(Parser, Debug)]
#[command(author, version, about, long_about=None)]
struct Cli {
@ -46,21 +48,7 @@ fn main() {
println!("Music directory is: {:?}", dirs_next::audio_dir());
}
// ScanDir::dirs()
// and
// ScanDir::files()
//iter.filter(|&(_, ref name)| name.ends_with(".rs"))
// .map(|(ref entry, _)| entry.path())
// .collect()
file_operations::scan_music_dir(music_dir).unwrap();
let files = ScanDir::dirs()
.read(music_dir, |iter| {
for (entry, name) in iter {
println!("File {:?} has full path {:?}", name, entry.path());
}
})
.unwrap();
println!("Hello, world!");
println!("{:?}", cli);
}