Rename
Rename Change the name of a file or directory
#include <Files.h> File Manager
OSErr Rename(oldName, vRefNum, newName );
Str255 oldName ; address of length-prefixed name of file to rename
short vRefNum ; volume or working directory reference
Str255 newName ; address of length-prefixed desired new name
returns Error Code; 0=no error
Rename renames a file or directory. This simply changes the text of the
name; it cannot be used to move a file to a different directory (see
PBCatMove).
oldName is the address of a length-prefixed, pascal-style string containing
the current name of the file or directory (directory names should
end with a colon ":").
vRefNum is the reference number of the volume or working directory that
contains the file or directory fileName. Use 0 to specify the default
volume.
newName is the address of a length-prefixed, pascal-style string containing
the desired new name for the file or directory (directory names
should end with a colon ":").
Returns: an operating system Error Code. It will be one of:
noErr (0) No error
bdNamErr (-37) Bad name, newName is different type from oldName
dirFulErr (-33) Directory full
dirNFErr (-120) Directory not found
dupFNErr (-48) Duplicate filename (newName already exists)
extFSErr (-58) External file system
fLckdErr (-45) File is locked
fnfErr (-43) File not found
fsRnErr (-59) Rename error
ioErr (-36) I/O error
nsvErr (-35) No such volume
paramErr (-50) No default volume
vLckdErr (-46) Volume is locked
wPrErr (-44) Diskette is write-protected

Notes: The vRefNum parameter describes the volume or directory in which the
item to rename currently resides. You may use a "hard" volume number,
or a working directory reference as returned by Standard File.
Both filenames must resolve to entries in the same directory; i.e., if
oldName is a fully-qualified three-name pathspec, then newName must
also provide that same information, with only the final element in the name
changing. For instance:
Rename( "\pHardDisk:Ltrs:Smith", 0, "\pHardDisk:Ltrs:Jones" );
When you rename a directory or volume, both names should end in a colon,
e.g.:
Rename( "\pHardDisk:", 0, "\pEasyDisk:" );
Perhaps the most common use of this function is when making a backup of a
document or other file before saving a changed version. You can simply
rename the old version then save the modified file with the original name;
e.g.:
err = Rename( "\pHdDsk:Ltrs:Smith", 0, "\pHdDsk:Ltrs:CopyOf Smith" );
if (rc == dupFNErr ) {
Rename("\pHdDsk:Ltrs:Smith",0,"\pHdDsk:Ltrs:CopyOf CopyOf Smith");
}
else { . . . handle the error . . . }
MySaveFile( "\pHardDisk:Ltrs:Smith" );
The low-level PBCatMove function lets you move a file into a different
directory (a sensible alternative to copying the file data and deleting the
original). The low-level version of this command is PBRename and the
HFS-specific version is PBHRename.
This function fails if the file or volume is locked or if a file having the
name newName already exists in the specified directory.