Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Turbo C - <b>rename() rename a file or directory</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
rename()                 Rename a File or Directory

 #include   <io.h>                       Required for declarations only
 #include   <stdio.h>                    Use either io.h or stdio.h

 int        rename(oldname,newname);
 char       *oldname;                    Pointer to old name
 char       *newname;                    Pointer to new name

    rename() renames the file or directory specified by 'oldname' to
    'newname'.

    Returns:    Zero if successful; or a non-zero value if an error
                occurs. On error, 'errno' (defined in <stdlib.h>) is set
                to either:

                    EACCES:    'newname' already exists; or an invalid
                               path was specified
                    ENOENT:    'oldname' not found
                    EXDEV:     attempt to move a file to a different
                               device

      Notes:    'oldname' must be the name of an existing file or
                directory. 'newname' must not already exist.  Directories
                can only be renamed. They cannot be moved.

  -------------------------------- Example ---------------------------------

    Example: This example changes the file name 'sales.dat' to
    'oldsales.dat', in effect moving it to a backup directory.

         #include <io.h>
         #include <stdio.h>

         main()
         {
               if ((rename("sales.dat","c:\bakup\oldsales.dat")) == 0)
                  printf("last week's sales file moved to backup directory");
         }

See Also: creat() fopen() open()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson