use crate::*;
pub fn copy_file(src: &str, dest: &str) -> Result<(), Error> {
std::fs::copy(src, dest)?;
Ok(())
}
pub fn copy_dir_files(src_dir: &str, dest_dir: &str) -> Result<(), Error> {
let src_path: &Path = Path::new(src_dir);
let dest_path: &Path = Path::new(dest_dir);
if dest_path.exists()
&& let Some(dest_path_str) = dest_path.to_str()
{
if dest_path.is_file() {
delete_file(dest_path_str)?;
}
if dest_path.is_dir() {
delete_dir(dest_path_str)?;
}
}
std::fs::create_dir_all(dest_path)?;
for entry in std::fs::read_dir(src_path)? {
let entry: DirEntry = entry?;
let file_name: OsString = entry.file_name();
let src_file_path: PathBuf = entry.path();
let mut dest_file_path: PathBuf = PathBuf::from(dest_path);
dest_file_path.push(file_name);
if src_file_path.is_dir() {
copy_dir_files(
src_file_path.to_str().unwrap(),
dest_file_path.to_str().unwrap(),
)?;
} else if src_file_path.is_file() {
std::fs::copy(&src_file_path, &dest_file_path)?;
}
}
Ok(())
}