C/File/File Rename

Материал из C\C++ эксперт
Перейти к: навигация, поиск

Rename a file

#include <stdio.h>
int main(void)
{
  if(rename("my.txt", "your.txt")) 
    printf("Rename failed.\n");
  else
    printf("Rename successful.\n");
  return 0;
}


Rename a file or directory: how to use rename

#include <stdio.h>
int main ()
{
  int result;
  
  char oldname[] ="old.txt";
  char newname[] ="new.txt";
  
  result= rename( oldname , newname );
  
  if (result != 0 )
    perror( "Error renaming file" );
  
  return 0;
}