mirror of
https://github.com/TECHNOFAB11/pay-respects.git
synced 2025-12-12 22:40:09 +01:00
feat: all parse in compilation
This commit is contained in:
parent
511b309d99
commit
53c7e1fd7b
8 changed files with 410 additions and 321 deletions
41
src/files.rs
Normal file
41
src/files.rs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
pub fn get_path_files() -> Vec<String> {
|
||||
let path = std::env::var("PATH").unwrap();
|
||||
let path = path.split(':').collect::<Vec<&str>>();
|
||||
let mut all_executable = vec![];
|
||||
for p in path {
|
||||
let files = match std::fs::read_dir(p) {
|
||||
Ok(files) => files,
|
||||
Err(_) => continue,
|
||||
};
|
||||
for file in files {
|
||||
let file = file.unwrap();
|
||||
let file_name = file.file_name().into_string().unwrap();
|
||||
all_executable.push(file_name);
|
||||
}
|
||||
}
|
||||
all_executable
|
||||
}
|
||||
|
||||
pub fn get_directory_files(input: &str) -> Vec<String> {
|
||||
let mut input = input.trim_matches(|c| c == '\'' || c == '"').to_owned();
|
||||
let files = loop {
|
||||
match std::fs::read_dir(&input) {
|
||||
Ok(files) => break files,
|
||||
Err(_) => {
|
||||
if let Some((dirs, _)) = input.rsplit_once('/') {
|
||||
input = dirs.to_owned();
|
||||
} else {
|
||||
break std::fs::read_dir("./").unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let mut all_files = vec![];
|
||||
for file in files {
|
||||
let file = file.unwrap();
|
||||
let file_name = file.path().to_str().unwrap().to_owned();
|
||||
all_files.push(file_name);
|
||||
}
|
||||
all_files
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue