feat: add ability to pass path argument
This commit is contained in:
@@ -6,3 +6,4 @@ edition = "2018"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
colored = "2.0.0"
|
||||||
31
src/main.rs
31
src/main.rs
@@ -1,12 +1,33 @@
|
|||||||
use std::fs;
|
use std::fs;
|
||||||
|
use std::env;
|
||||||
|
use colored::Colorize;
|
||||||
|
|
||||||
|
// \x1b is used to print in red
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let paths = fs::read_dir(".").unwrap();
|
let args: Vec<String> = env::args().collect();
|
||||||
|
if args.len() != 2 {
|
||||||
|
println!("{}", "ERR: Invalid number of arguments provided".red());
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
for result in paths {
|
let is_ok = fs::metadata(args[1].to_owned()).is_ok();
|
||||||
let path = result.unwrap().path();
|
if !is_ok {
|
||||||
let metadata = fs::metadata(path.to_str().unwrap()).unwrap();
|
println!("{}", "ERR: Path provided does not exist".red());
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let is_dir = fs::metadata(args[1].to_owned()).unwrap().is_dir();
|
||||||
|
if !is_dir {
|
||||||
|
println!("{}", "ERR: Path provided is not a directory".red());
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let objects = fs::read_dir(args[1].to_owned()).unwrap();
|
||||||
|
for result in objects {
|
||||||
|
let object = result.unwrap().path();
|
||||||
|
let metadata = fs::metadata(object.to_str().unwrap()).unwrap();
|
||||||
let type_ = if metadata.is_dir() { "Dirc" } else { "File" };
|
let type_ = if metadata.is_dir() { "Dirc" } else { "File" };
|
||||||
println!("{}: {}", type_, path.display())
|
println!("{}: {}", type_, object.display())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user