file_operation/move/sync/
fn.rs1use crate::*;
2
3pub fn move_file(src: &str, dest: &str) -> Result<(), std::io::Error> {
14 std::fs::rename(src, dest)?;
15 Ok(())
16}
17
18pub fn move_dir(src_dir: &str, dest_dir: &str) -> Result<(), std::io::Error> {
29 let src_path: &Path = Path::new(src_dir);
30 let dest_path: &Path = Path::new(dest_dir);
31 if dest_path.exists() {
32 std::fs::remove_dir_all(dest_path)?;
33 }
34 std::fs::create_dir_all(dest_path)?;
35 for entry in std::fs::read_dir(src_path)? {
36 let entry: std::fs::DirEntry = entry?;
37 let file_name: OsString = entry.file_name();
38 let src_file_path: PathBuf = entry.path();
39 let mut dest_file_path: PathBuf = PathBuf::from(dest_path);
40 dest_file_path.push(file_name);
41 if src_file_path.is_dir() {
42 move_dir(
43 src_file_path.to_str().unwrap(),
44 dest_file_path.to_str().unwrap(),
45 )?;
46 } else if src_file_path.is_file() {
47 std::fs::rename(&src_file_path, &dest_file_path)?;
48 }
49 }
50 std::fs::remove_dir(src_path)?;
51 Ok(())
52}