From f55ae521a0b3ee730af723bbdfd115c28d3d1eda Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 11 Mar 2014 22:31:34 +0700 Subject: enhance cp command to accept dest path as an folder --- demos/host/src/cli.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'demos/host/src/cli.c') diff --git a/demos/host/src/cli.c b/demos/host/src/cli.c index d67379b9b..4cb33e060 100644 --- a/demos/host/src/cli.c +++ b/demos/host/src/cli.c @@ -396,19 +396,30 @@ cli_error_t cli_cmd_copy(char *p_para) drive_letter2number(p_para); drive_letter2number(p_dest); - //------------- Check Existence of source & dest file -------------// + //------------- Check Existence of source file -------------// + FIL src_file; + if ( FR_OK != f_open(&src_file , p_para, FA_READ) ) return CLI_ERROR_INVALID_PATH; + + //------------- Check if dest path is a folder or a non-existing file (overwritten is not allowed) -------------// + FILINFO dest_entry; + if ( (f_stat(p_dest, &dest_entry) == FR_OK) && (dest_entry.fattrib & AM_DIR) ) + { // the destination is an existed folder --> auto append dest filename to be the folder + strcat(p_dest, "/"); + strcat(p_dest, p_para); + } + + //------------- Open dest file and start the copy -------------// cli_error_t error = CLI_ERROR_NONE; - FIL src_file, dest_file; + FIL dest_file; - if ( FR_OK != f_open(&src_file , p_para, FA_READ) ) return CLI_ERROR_INVALID_PATH; switch ( f_open(&dest_file, p_dest, FA_WRITE | FA_CREATE_NEW) ) { case FR_EXIST: error = CLI_ERROR_FILE_EXISTED; - break;\ + break; case FR_OK: - while(1) + while(1) // copying { uint32_t bytes_read = 0; uint32_t bytes_write = 0; -- cgit v1.3.1