mv.rs
1 use core::fmt::Write; 2 use alloc::string::String as AllocString; 3 use crate::filesystems::sd::{copy_file, delete_file}; 4 5 pub fn run(args: &str) -> AllocString { 6 let parts: heapless::Vec<&str, 2> = args.splitn(2, ' ').collect(); 7 if parts.len() < 2 { 8 return super::fmt_usage("mv <src> <dst>"); 9 } 10 11 let src = parts[0].trim(); 12 let dst = parts[1].trim(); 13 14 match copy_file(src, dst) { 15 Ok(bytes) => match delete_file(src) { 16 Ok(()) => { 17 let mut out = AllocString::new(); 18 let _ = write!(out, "moved {} -> {} ({} bytes)\r\n", src, dst, bytes); 19 out 20 } 21 Err(error) => super::fmt_error(&error), 22 }, 23 Err(error) => super::fmt_error(&error), 24 } 25 }