└── cli /cli: -------------------------------------------------------------------------------- 1 | 2 | **Code** (`src/main.rs`): 3 | ```rust 4 | use std::env; 5 | use std::fs::{self, File}; 6 | use std::io::{self, Write}; 7 | use std::path::Path; 8 | 9 | fn list_files(path: &str) -> io::Result<()> { 10 | let entries = fs::read_dir(path)?; 11 | for entry in entries { 12 | let entry = entry?; 13 | println!("{}", entry.path().display()); 14 | } 15 | Ok(()) 16 | } 17 | 18 | fn copy_file(src: &str, dest: &str) -> io::Result<()> { 19 | fs::copy(src, dest)?; 20 | Ok(()) 21 | } 22 | 23 | fn move_file(src: &str, dest: &str) -> io::Result<()> { 24 | fs::rename(src, dest)?; 25 | Ok(()) 26 | } 27 | 28 | fn delete_file(path: &str) -> io::Result<()> { 29 | fs::remove_file(path)?; 30 | Ok(()) 31 | } 32 | 33 | fn main() { 34 | let args: Vec = env::args().collect(); 35 | let command = &args[1]; 36 | 37 | match command.as_str() { 38 | "list" => { 39 | if let Err(e) = list_files(".") { 40 | eprintln!("Error listing files: {}", e); 41 | } 42 | } 43 | "copy" => { 44 | if let Err(e) = copy_file(&args[2], &args[3]) { 45 | eprintln!("Error copying file: {}", e); 46 | } 47 | } 48 | "move" => { 49 | if let Err(e) = move_file(&args[2], &args[3]) { 50 | eprintln!("Error moving file: {}", e); 51 | } 52 | } 53 | "delete" => { 54 | if let Err(e) = delete_file(&args[2]) { 55 | eprintln!("Error deleting file: {}", e); 56 | } 57 | } 58 | _ => eprintln!("Invalid command"), 59 | } 60 | } 61 | --------------------------------------------------------------------------------