Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 3/22/2024
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

RENAME

Portability Function: Renames a file.

Module

USE IFPORT

result = RENAME (from,to)

from

(Input) Character*(*). Path of an existing file.

to

(Input) Character*(*). The new path for the file (see Caution note below).

Results

The result type is INTEGER(4). The result is zero if successful; otherwise, an error code, such as:

  • EACCES - The file or directory specified by to could not be created (invalid path). This error is also returned if the drive specified is not currently connected to a device.

  • ENOENT - The file or path specified by from could not be found.

  • EXDEV - Attempt to move a file to a different device.

CAUTION:

This routine can cause data to be lost. If the file specified in to already exists, RENAME deletes the pre-existing file.

It is possible to rename a file to itself without error.

The paths can use forward (/) or backward (\) slashes as path separators and can include drive letters (if permitted by your operating system).

Example

 use IFPORT
 integer(4) istatus
 character*12 old_name, new_name
 print *, "Enter file to rename: "
 read *, old_name
 print *, "Enter new name: "
 read *, new_name
 ISTATUS = RENAME (old_name, new_name)

See Also