[<<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()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility. Written by Dave Pearson