So for this I have to copy a file or folder from destination to source and then erase the source file or folder. I don't know how to copy physical a file or folder.
This is my code, but I need another method, can you help me please ?
I need the function mv -i, -t, -s
What I have tried:
void mv_i()
{
int mutat;
char *mvFile_name1;
char *mvFile_name2;
char answerMv[100];
mvFile_name1=params[2];
mvFile_name2=params[3];
printf("Are you sure you want to move %s into %s?", mvFile_name1, mvFile_name2);
scanf("%s", answerMv);
if(answerMv[0] == 'y')
{
mutat = rename(mvFile_name1, mvFile_name2);
if(mutat != 0)
{
perror("Error");
}
}
}
void mv_files()
{
int mutat;
char mvFile_name1[30];
char mvFile_name2[30];
printf("The file you want to move: ");
scanf("%s", mvFile_name1);
printf("The location file: ");
scanf("%s", mvFile_name2);
mutat = rename(mvFile_name1, mvFile_name2);
if(mutat != 0)
perror("Error");
}
void mv_t()
{
int mutat;
char mvFile_name1[256];
char mvFile_name2[256];
char *locatie1="";
char *locatie2="";
int nr=0;
locatie1=malloc(sizeof(char*));
locatie2=malloc(sizeof(char*));
printf("How many files you want to move: ");
scanf("%d", &nr);
printf("The file where you move: ");
scanf("%s", mvFile_name2);
strcpy(locatie2, mvFile_name2);
for(i=0; i<nr;> {
printf("The file you want to move: ");
scanf("%s", mvFile_name1);
strcpy(locatie1, mvFile_name1);
mutat = rename(locatie2, locatie1);
if(mutat != 0)
perror("Error");
}
}