diff options
| author | hathach <[email protected]> | 2022-11-21 11:24:58 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2022-11-21 11:24:58 +0700 |
| commit | 51873cd1be5291c15a24054e464d98d4953eebfa (patch) | |
| tree | 100f4e87e9f61db3d0f3989fceb3c246a8dfd03d /examples | |
| parent | 47bc269b50eb0fab9ac2f708cecdce2e2df601d9 (diff) | |
implement rm command
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/host/msc_file_explorer/src/msc_app.c | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/examples/host/msc_file_explorer/src/msc_app.c b/examples/host/msc_file_explorer/src/msc_app.c index a1822b422..4500aedd2 100644 --- a/examples/host/msc_file_explorer/src/msc_app.c +++ b/examples/host/msc_file_explorer/src/msc_app.c @@ -275,6 +275,7 @@ void cli_cmd_cp(EmbeddedCli *cli, char *args, void *context); void cli_cmd_ls(EmbeddedCli *cli, char *args, void *context); void cli_cmd_mkdir(EmbeddedCli *cli, char *args, void *context); void cli_cmd_mv(EmbeddedCli *cli, char *args, void *context); +void cli_cmd_rm(EmbeddedCli *cli, char *args, void *context); void cli_write_char(EmbeddedCli *cli, char c) { @@ -347,12 +348,20 @@ bool cli_init(void) embeddedCliAddBinding(_cli, (CliCommandBinding) { "mv", - "Usage: mv SOURCE DEST...\r\n\tRename SOURCE to DEST", + "Usage: mv SOURCE DEST...\r\n\tRename SOURCE to DEST.", true, NULL, cli_cmd_mv }); + embeddedCliAddBinding(_cli, (CliCommandBinding) { + "rm", + "Usage: rm [FILE]...\r\n\tRemove (unlink) the FILE(s).", + true, + NULL, + cli_cmd_rm + }); + return true; } @@ -566,3 +575,27 @@ void cli_cmd_mv(EmbeddedCli *cli, char *args, void *context) return; } } + +void cli_cmd_rm(EmbeddedCli *cli, char *args, void *context) +{ + (void) cli; (void) context; + + uint16_t argc = embeddedCliGetTokenCount(args); + + // need at least 1 argument + if ( argc == 0 ) + { + printf("invalid arguments\r\n"); + return; + } + + for(uint16_t i=0; i<argc; i++) + { + const char* fpath = embeddedCliGetToken(args, i+1); // token count from 1 + + if ( FR_OK != f_unlink(fpath) ) + { + printf("cannot remove '%s': No such file or directory\r\n", fpath); + } + } +} |
