rename
raw OCR
Renames a file.
Defined in header <stdio.h>
Syntax
#include <stdio.h>
int renameCconst char *oldname, const char *newname);
Portability
| DOS | UNIX | Windows | ANSI C | C++ only |
|---|---|---|---|---|
| ■ | ■ | ■ |
Remarks
rename changes the name of a file from oldname to newname. If a drive specifier is given in newname, the specifier must be the same as that given in oldname.
Directories in oldname and newname need not be the same, so rename can be used to move a file from one directory to another. Wildcards are not allowed.
Return value
On successfully renaming the file, rename returns 0. In the event of error, -1 is returned, and the global variable errno is set to one of the following:
| ENOENT | No such file or directory |
| EACCES | Permission denied |
| ENOTSAM | Not same device |
Example
#include <stdio.h>
int main(void)
{
char oldname [801
/* prompt for file to rename and new name */
printfC'File to rename: ");
gets(oldname) ;
printf("New name: ");
gets (newname);
/* rename the file */
if (rename(oldname, newname) == 0)
printf ("Renamed %s to %s.\n", oldname, newname);
else
perror("rename") ;
return 0;
Differences from modern implementations
Nothing recorded yet.
Modern references
These are search links, not yet checked by hand.
Stable link: /3.1/stdio.h/rename/
· short form /3.1/rename/