mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-16 17:14:36 +01:00
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:
@@ -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
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user