Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C 6.0 - <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 stdio.h for ANSI compatibility

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

    rename() changes the name of an existing file or directory from
    'oldname' to 'newname'.

    Returns:    Zero if successful.  On error, a non-zero value is
                returned and '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' cannot already exist.  Directories
                can be renamed, but cannot be moved.

 Compatibility: MSC version 4.0 required the arguments to be in the
                reverse order; the change was made to conform to ANSI
                standard.

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

    Example: This example changes the file name 'sales.dat' to
    'oldsales.dat', in fact 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