use std::fs;
use std::path::{Path, PathBuf};
pub fn file_exists(file_path: &str) -> bool {
let path = PathBuf::from(file_path);
Path::new(&path).is_file()
}
pub fn delete_file(file: &str) {
let _ = fs::remove_file(file);
}
pub fn delete_files_with_ext(dir: &str, extension: &str) -> std::io::Result<()> {
let files = fs::read_dir(dir)?;
for file in files {
let file = file?;
let path = file.path();
if path.is_file() {
if let Some(ext) = path.extension() {
if ext == extension {
delete_file(&path.to_string_lossy());
}
}
}
}
Ok(())
}
pub fn dir_exists(dir_path: &str) -> bool {
let path = PathBuf::from(dir_path);
Path::new(&path).is_dir()
}
pub fn delete_dir(dir: &str) {
let _ = fs::remove_dir_all(dir);
}