-
Notifications
You must be signed in to change notification settings - Fork 0
/
new_folder_rusty.rs
103 lines (88 loc) · 2.94 KB
/
new_folder_rusty.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
use std::fs;
use std::path::PathBuf;
use std::process::Command;
// hide root window
let root = Tk::root();
root.withdraw();
// hide root window
let root = Tk::root();
root.withdraw();
// Intro guide messagebox
showinfo("info", "Selecione onde será salva a task.");
// Shows dialog box and return the path
let path: String = askdirectory(initialdir = "C:\\Users\\RodrigoMC\\Desktop", title = "Pasta destino")?;
println!("{}", path);
// Creates the folder
let current_dir: PathBuf = fs::canonicalize(".")?.join(path);
if !current_dir.exists() {
fs::create_dir(¤t_dir)?;
}
// Asks the folder name
let userStr: String = simpledialog("Criar pasta", "Cole o título da task no Collab aqui.")?;
// Cleans the folder name
let cleanStr1: String = userStr.replace(":", "-");
let cleanStr2: String = cleanStr1.replace("/", "-");
let cleanStr3: String = cleanStr2.replace(".", "-");
let cleanStr4: String = cleanStr2.replace("|", "-");
let new_folder: String = format!("{}{}", userStr, "/00_materiais/01_layout/02_view");
// Tests if the folder a ready exists
if !current_dir.join(&new_folder).exists() {
// Creates the subfolders
let mut command = Command::new("mkdir")
.arg("-p")
.args(&[&new_folder])
.current_dir(PathBuf::from(¤t_dir));
if !command.status()?.success() {
eprintln!("{}", command);
return;
}
// Success feedback
showinfo("info", "Sucesso Total!");
} else {
// Error feedback
showinfo(
"info",
"Erro: A pasta já existe! \
Verifique o nome da task.",
);
}
// Intro guide messagebox
showinfo("info", "Selecione onde será salva a task.");
// Shows dialog box and return the path
let path = askdirectory(initialdir = "C:\\Users\\RodrigoMC\\Desktop", title = "Pasta destino").unwrap();
println!("{}", path);
// Creates the folder
let current_dir: PathBuf = fs::canonicalize(".")?;
let new_path: PathBuf = current_dir.join(path);
if !new_path.exists() {
fs::create_dir(&new_path)?;
}
// Asks the folder name
let userStr = simpledialog("Criar pasta", "Cole o título da task no Collab aqui.");
// Cleans the folder name
let cleanStr1 = userStr.replace(":", "-");
let cleanStr2 = cleanStr1.replace("/", "-");
let cleanStr3 = cleanStr2.replace(".", "-");
let cleanStr4 = cleanStr2.replace("|", "-");
let new_folder: String = format!("{}{}", userStr, "/00_materiais/01_layout/02_view");
// Tests if the folder a ready exists
if !new_path.join(&new_folder).exists() {
// Creates the subfolders
let mut command = Command::new("mkdir")
.arg("-p")
.args(&[&new_folder])
.current_dir(PathBuf::from(&new_path));
if !command.status()?.success() {
eprintln!("{}", command);
return;
}
// Success feedback
showinfo("info", "Sucesso Total!");
} else {
// Error feedback
showinfo(
"info",
"Erro: A pasta já existe! \
Verifique o nome da task.",
);
}