Sun Studio 12: Fortran Library Reference

1.4.42 rename: Rename a File

The function is called by:

INTEGER*4 rename

status = rename( from, to )

from

character*n

Input 

Path name of an existing file 

to

character*n

Input 

New path name for the file 

Return value 

INTEGER*4

Output 

status=0: OK

status>0: System error code

If the file specified by to exists, then both from and to must be the same type of file, and must reside on the same file system. If to exists, it is removed first.

Example: rename()—Rename file trename.old to trename.new


demo% cat trename.f
       INTEGER*4 rename, status
       character*18 from/’trename.old’/, to/’trename.new’/
       status = rename( from, to )
       if ( status .ne. 0 ) stop ’rename: error’
       end
demo% f95 trename.f
demo% ls trename*
trename.f trename.old
demo% a.out
demo% ls trename*
trename.f trename.new
demo%

See also rename(2) and perror(3F).

Note: the path names cannot be longer than MAXPATHLEN as defined in <sys/param.h>.