Renaming a file or directory

rename()

Rename a file or directory


SYNTAX

rename(oldname, newname)

Rename the file or directory specified in oldname to newname. Both oldname and newname must be of the same type, i.e. both must be files or both must be directories.

If oldname refers to a file on a server, then newname must refer to the same server or omit the server name, in which case it is assumed to refer to the same server. Pathnames can be absolute or relative to the current working directory, but it is generally necessary to use absolute pathnames when renaming files on a server. The following two calls are equivalent:

rename(“myserver:c:/app/data/old.d”, “c:/app/data/new.d”)
rename(“myserver:c:/app/data/old.d”, “myserver:c:/app/data/new.d”)

A file can be moved and/or renamed to a different directory, provided that they are part of the same file system. Under MS-DOS, this means that they must be on the same drive, as in the second example below.

Under MS-DOS, a directory can be renamed but cannot be moved to a new part of the file system tree. In other words, only the last component of the pathname can be changed. Under UNIX a directory can be renamed to a new part of the same file system.

Under UNIX, the user must have write permission for the file or directory being renamed. If renaming on a server, then the user who started kfserver must have the required permission. Sculptor’s client/server security feature can be used to impose restrictions by client. The rename() function is classed as a general file operation.

There are no permissions restrictions under MS-DOS.

The function returns 0 if successful. If unsuccessful it returns a negative value and stores the system error code in sys.Errno.


EXAMPLES

rename("C:/apps/office/xrefdir", "C:/apps/office/xfiledir")
rename("c:/olddir/fileoldname", "c:/newdir/filenewname")
!temp Status,,i2

     NewDDPath = DestName / ".d"
     Status = (rename(FullDDPath, NewDDPath))

     if (Status <> 0) {
          error "Unable to rename data dictionary - operating system error " + tostr(sys.Errno)
     }

RELATED TOPICS

File and directory handling functions