Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Borland C++ 2.x ( with 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   <stdio.h>

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

    rename() renames a file or directory, changing the name from
    'oldname' to 'newname'.

       Returns:     0, if successful or a -1 value if an error occurs. On
                    error, 'errno' (defined in <errno.h>) is set to:

                    EACCES:    'newname' already exists; or an invalid
                               path was specified
                    ENOENT:    'oldname' not found
                    ENOTSAM:   not the same device

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

   Portability:     MS-DOS only.

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

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

           #include <stdio.h>

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


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

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