List a directory
(current_directory: &Path, args: &[&str])
| 83 | |
| 84 | /// List a directory |
| 85 | fn 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 |
| 112 | fn umount(args: &[&str]) { |