the-honkers-railway-launcher/src/move_folder.rs
Observer KRypt0n_ f66111f8e9
feat: preparations for upcoming 3.6 changes
Added support for the game files structure updating mechanism
form the latest launcher SDK. Also added
new progress bar statuses for applyign hdiff patches
and removing outdated files
2023-04-11 20:08:54 +02:00

26 lines
597 B
Rust

use std::path::Path;
pub fn move_folder(from: &Path, to: &Path) -> std::io::Result<()> {
if !to.exists() {
std::fs::create_dir_all(to)?;
}
for entry in from.read_dir()?.flatten() {
let to_path = to.join(entry.file_name());
if entry.metadata()?.is_dir() {
move_folder(&entry.path(), &to_path)?;
}
else if entry.metadata()?.is_file() {
std::fs::copy(entry.path(), to_path)?;
std::fs::remove_file(entry.path())?;
}
// TODO: symlinks?
}
std::fs::remove_dir_all(from)?;
Ok(())
}