Move things to file_helpers

These were meant to be here anyway but I didn't put it here because other similar methods were in system_helpers
This commit is contained in:
Benj
2022-07-12 14:28:08 +08:00
parent ba2a8b7fec
commit a703843eed
5 changed files with 54 additions and 35 deletions

View File

@@ -59,3 +59,33 @@ pub fn copy_file(path: String, new_path: String) -> bool {
}
}
}
#[tauri::command]
pub fn copy_file_with_new_name(path: String, new_path: String, new_name: String) -> bool {
let mut new_path_buf = std::path::PathBuf::from(&new_path);
// If the new path doesn't exist, create it.
if !dir_exists(new_path_buf.pop().to_string().as_str()) {
std::fs::create_dir_all(&new_path).unwrap();
}
// Copy old to new
match std::fs::copy(&path, format!("{}/{}", new_path, new_name)) {
Ok(_) => true,
Err(e) => {
println!("Failed to copy file: {}", e);
false
}
}
}
#[tauri::command]
pub fn delete_file(path: String) -> bool {
match std::fs::remove_file(path) {
Ok(_) => return true,
Err(e) => {
println!("Failed to delete file: {}", e);
return false
}
};
}