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:
parent
2dfd4aef4f
commit
4b1b6e7648
2 changed files with 41 additions and 15 deletions
38
src/file_operations.rs
Normal file
38
src/file_operations.rs
Normal 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(())
|
||||||
|
}
|
18
src/main.rs
18
src/main.rs
|
@ -2,6 +2,8 @@ use clap::Parser;
|
||||||
use dirs_next;
|
use dirs_next;
|
||||||
use scan_dir::ScanDir;
|
use scan_dir::ScanDir;
|
||||||
|
|
||||||
|
pub mod file_operations;
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[command(author, version, about, long_about=None)]
|
#[command(author, version, about, long_about=None)]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
|
@ -46,21 +48,7 @@ fn main() {
|
||||||
println!("Music directory is: {:?}", dirs_next::audio_dir());
|
println!("Music directory is: {:?}", dirs_next::audio_dir());
|
||||||
}
|
}
|
||||||
|
|
||||||
// ScanDir::dirs()
|
file_operations::scan_music_dir(music_dir).unwrap();
|
||||||
// and
|
|
||||||
// ScanDir::files()
|
|
||||||
//iter.filter(|&(_, ref name)| name.ends_with(".rs"))
|
|
||||||
// .map(|(ref entry, _)| entry.path())
|
|
||||||
// .collect()
|
|
||||||
|
|
||||||
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);
|
println!("{:?}", cli);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue