MCPcopy Create free account
hub / github.com/bendudson/EuraliOS / ls

Function ls

shell/src/main.rs:85–109  ·  view source on GitHub ↗

List a directory

(current_directory: &Path, args: &[&str])

Source from the content-addressed store, hash-verified

83
84/// List a directory
85fn ls(current_directory: &Path, args: &[&str]) {
86 if args.len() > 1 {
87 println!("Usage: ls [path]");
88 return;
89 }
90
91 let option_rd = if args.len() == 0 {
92 fs::read_dir(current_directory)
93 } else {
94 let path = fs::canonicalize(PathBuf::from(current_directory).join(args[0])).unwrap();
95 fs::read_dir(path)
96 };
97
98 if let Ok(rd) = option_rd {
99 for entry in rd {
100 if let Ok(obj) = entry {
101 if obj.metadata().unwrap().is_dir() {
102 println!("\x1b[34m{}\x1b[m", obj.file_name());
103 } else {
104 println!("{}", obj.file_name());
105 }
106 }
107 }
108 }
109}
110
111/// Unmount a path
112fn umount(args: &[&str]) {

Callers 1

mainFunction · 0.85

Calls 6

read_dirFunction · 0.85
canonicalizeFunction · 0.85
joinMethod · 0.80
is_dirMethod · 0.80
metadataMethod · 0.80
lenMethod · 0.45

Tested by

no test coverage detected