manipulation_archive/
archive.rs1#[allow(dead_code)]
2pub mod archive_mod{
3 use std::fs::rename;
4 use std::io::{Read};
5 use std::fs::File;
6 use std::io::Write;
7 use std::path::Path;
8
9 pub fn create_archive_rs(path: &'static str) -> File{
10 let path_completo = Path::new(path).join(".rs");
11 if !path_completo.exists() || path.is_empty() || !path.ends_with(".rs"){
12 return File::create("src/default.rs").expect("Create archive filed!!!");
13 }
14 else{
15 return File::create(path_completo).expect("Create archive filed!!!");
16 }
17 }
18
19 pub fn write_code_rust(code: &'static str, mut file: File){
20 file.write_all(code.as_bytes()).expect("Write code failed!");
21 }
22
23 pub fn write_word_txt(text: &'static str, mut file: File){
24 file.write_all(text.as_bytes()).expect("Write failed!");
25 }
26
27 pub fn create_archive_txt(path: &'static str) -> File{
28 if path.is_empty() && !path.contains(".txt"){
29 return File::create("src/example.txt").expect("Create archive filed!!!");
30 }
31 else{
32 return File::create(path).expect("Create archive filed!!!");
33 }
34 }
35 pub fn read_archive(path: &'static str) -> String{
36 if !Path::exists(Path::new(path)){
37 panic!("Path invalid!");
38 }
39 else{
40 let mut string_read_archive = String::from(path);
41 let mut file = File::open(path).unwrap();
42 file.read_to_string(&mut string_read_archive).unwrap();
43 return string_read_archive;
44 }
45 }
46
47 pub fn rename_archive(path_from: &'static str, path_to: &'static str){
48 if !Path::exists(&Path::new(path_from)) && !Path::exists(&Path::new(path_to)){
49 panic!("Path inválido!!!");
50 }else {
51 rename(path_from, path_to).expect("File not found.");
52 }
53 }
54
55}