kolibrios/programs/system/shell/cmd/cmd_ren.c
Rustem Gimadutdinov (rgimad) b8b18f32a0 SHELL 0.8 changelog
- added mv command
- added ren command
- now ls works also with relative pathes
- fixed bug in strrchr

git-svn-id: svn://kolibrios.org@7802 a494cfbc-eb01-0410-851d-a64ba20cac60
2020-04-16 21:50:49 +00:00

51 lines
1.2 KiB
C
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

int cmd_ren(char param[])
{
char* argv[100];
int argc;
/*
argv[0] - path (abs or rel) to file
argv[1] - new filename
*/
argc = parameters_prepare(param, argv);
if (argc != 2)
{
#if LANG_ENG
printf(" ren <file> <new_name>\n\r");
#elif LANG_RUS
printf(" ren <ä ©«> <­®¢®¥_¨¬ï>\n\r");
#endif
parameters_free(argc, argv);
return TRUE;
}
char *x;
if (x = strrchr(argv[1], '/') != 0) // argv[1] must be file name, not path
{
//printf("%d %s", x, argv[1]);
return FALSE;
}
char *new_filename = (char*)malloc(FILENAME_MAX); new_filename[0] = '\0';
get_file_dir_loc(argv[0], new_filename);
if (strlen(new_filename) > 0)
{
strcat(new_filename, "/");
}
strcat(new_filename, argv[1]);
char *mv_params = (char*)malloc(FILENAME_MAX*2 + 1); mv_params[0] = '\0';
strcat(mv_params, argv[0]);
strcat(mv_params, " ");
strcat(mv_params, new_filename);
//printf("(%s)\n", mv_params);
int res = cmd_mv(mv_params);
free(new_filename);
free(mv_params);
return res;
}