I am trying to make a small application that backs up my files to a NAS at home. I am having issues with the fs::copy and fs::create_dir function. When it tries to make a folder or copy a folder with the character '.' in the path it fails and wont run
This is the code:
fn get_files(dir: &str, file_count: &mut u64) -> std::io::Result<()> {
match fs::read_dir(Path::new(&format!("{}{}", LOCAL_BASE, dir))) {
Ok(local_files) => {
for file in local_files{
let local_path = file.unwrap().path();
let fnas_dir = &format!("{}{}", FNAS_BASE, dir);
let fnas_path = Path::new(fnas_dir);
if local_path.to_str().unwrap().contains(".git") == false {
if local_path.is_dir(){
if fnas_path.exists() == false {
match fs::create_dir(fnas_path) {
Ok(_) => println!("Created new folder: {}", fnas_path.to_str().unwrap()),
Err(error) => println!("Folder: {}: {}", error, local_path.to_str().unwrap()),
}
}
get_files(&remove_starting_directory(local_path.to_str().unwrap()), file_count)?
}
else{
if fnas_path.exists() == false {
match fs::copy(&local_path, &fnas_path) {
Ok(_) => println!("Created file: {}", fnas_path.to_str().unwrap()),
Err(error) => println!("File: {}: {}", error, local_path.to_str().unwrap()),
}
}
}
}
}
}
Err(err) => {println!("Permission denied: {}", err)},
};
Ok(())
}
And this is the output it gives me
Created new folder: //fnas2/FTP/Jack/Documents/Computing/Rust\file_backup
Created file: //fnas2/FTP/Jack/Documents/Computing/Rust\file_backup.vscode
Created file: //fnas2/FTP/Jack/Documents/Computing/Rust\file_backup\src
Created file: //fnas2/FTP/Jack/Documents/Computing/Rust\file_backup\target
File: The system cannot find the path specified. (os error 3):
:\Documents\Computing\Rust\file_backup\target\debug.cargo-lock
Folder: The system cannot find the path specified. (os error 3): D:\Documents\Computing\Rust\file_backup\target\debug.fingerprint
Folder: The system cannot find the path specified. (os error 3): D:\Documents\Computing\Rust\file_backup\target\debug.fingerprint\aho-corasick-0608655a052e88a1
File: The system cannot find the path specified. (os error 3): D:\Documents\Computing\Rust\file_backup\target\debug.fingerprint\aho-corasick-0608655a052e88a1\dep-lib-aho_corasick
File: The system cannot find the path specified. (os error 3): D:\Documents\Computing\Rust\file_backup\target\debug.fingerprint\aho-corasick-0608655a052e88a1\invoked.timestamp
File: The system cannot find the path specified. (os error 3): D:\Documents\Computing\Rust\file_backup\target\debug.fingerprint\aho-corasick-0608655a052e88a1\lib-aho_corasick
File: The system cannot find the path specified. (os error 3): D:\Documents\Computing\Rust\file_backup\target\debug.fingerprint\aho-corasick-0608655a052e88a1\lib-aho_corasick.json
Folder: The system cannot find the path specified. (os error 3): D:\Documents\Computing\Rust\file_backup\target\debug.fingerprint\aho-corasick-32bba41e4cfc03c0