本文介绍了我想使用c从unix实现mv函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我必须将文件或文件夹从目标复制到源,然后删除源文件或文件夹。我不知道如何复制物理文件或文件夹。



这是我的代码,但我需要另一种方法,你可以帮我吗?



我需要函数mv -i,-t,-s



我尝试过:



 void mv_i()
{
int mutat;
char * mvFile_name1;
char * mvFile_name2;
char answerMv [100];

mvFile_name1 = params [2];
mvFile_name2 = params [3];

printf(你确定要将%s移到%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(你要移动的文件:);
//得到(mvFile_name1);
scanf(%s,mvFile_name1);
printf(位置文件:);
//得到(mvFile_name2);
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(你要移动多少个文件:);
scanf(%d,& nr);

printf(你搬家的文件:);
scanf(%s,mvFile_name2);

strcpy(locatie2,mvFile_name2);

for(i = 0; i< nr;> {
printf(你要移动的文件:);
scanf(%s,mvFile_name1 );

strcpy(locatie1,mvFile_name1);

mutat = rename(locatie2,locatie1);

if(mutat!= 0)
perror(错误);
}
}
解决方案

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: ");
  //gets(mvFile_name1);
  scanf("%s", mvFile_name1);
  printf("The location file: ");
  //gets(mvFile_name2);
  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");
  }
}
解决方案


这篇关于我想使用c从unix实现mv函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 20:57