use anyhow::{Ok, Result};
use std::{fs, io, path::PathBuf};
pub fn read_directory(path: &PathBuf) -> Result<Vec<PathBuf>> {
Ok(fs::read_dir(path)?
.into_iter()
.flatten()
.map(|e| e.path())
.collect())
}
pub fn move_to_directory(file: &PathBuf, dir: &PathBuf) -> Result<PathBuf> {
if !dir.is_dir() {
return Err(io::Error::new(
io::ErrorKind::NotADirectory,
"Cannot move file into a non-directory",
)
.into());
}
let newfile = dir.join(file);
fs::rename(file, &newfile)?;
Ok(newfile)
}