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");
}
Seealso:
This page last updated on Fri Nov 30 10:48:32 MSK 2001
Copyright © 1992-2001, Vitaly Filatov, Moscow, Russia
Webmaster