delete empty dirs
This commit is contained in:
parent
825482ba07
commit
7c26c38ccb
|
@ -45,7 +45,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "download-organiser"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
dependencies = [
|
||||
"dirs",
|
||||
"fs_extra",
|
||||
|
|
12
src/main.rs
12
src/main.rs
|
@ -1,5 +1,5 @@
|
|||
use std::fs::DirEntry;
|
||||
use std::io;
|
||||
use std::{fs, io};
|
||||
use std::path::PathBuf;
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
|
@ -83,6 +83,7 @@ fn handle_mp3(file: DirEntry) {
|
|||
|
||||
if let Some(tag) = meta.unwrap().tag {
|
||||
println!("----------------------");
|
||||
println!("file: {:?}", file.path());
|
||||
println!("artist: {}", tag.artist.trim());
|
||||
println!("album: {}", tag.album.trim());
|
||||
println!("title: {}", tag.title.trim());
|
||||
|
@ -152,10 +153,12 @@ fn handle_video(file: DirEntry) {
|
|||
}
|
||||
|
||||
fn handle_dir(path: PathBuf) {
|
||||
let dir = std::fs::read_dir(path).expect("Couldn't read dir");
|
||||
|
||||
// todo if dir is empty, delete
|
||||
let mut dir = std::fs::read_dir(&path).expect("Couldn't read dir");
|
||||
|
||||
if dir.next().is_none() {
|
||||
println!("Deleting empty dir: {:?}", path);
|
||||
fs::remove_dir(path).expect("Couldn't delete dir")
|
||||
} else {
|
||||
for inode in dir {
|
||||
let inode = inode.expect("Couldn't read inode");
|
||||
|
||||
|
@ -183,6 +186,7 @@ fn handle_dir(path: PathBuf) {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
handle_dir(downloads_dir());
|
||||
|
|
Loading…
Reference in New Issue