Tools: MPW
Advanced Search
Apple Developer Connection
Member Login Log In | Not a Member? Support

MPW Command Reference


Rename

Built-in

SYNTAX

Rename oldName newName [-c | -n | -y] [-resolve]

DESCRIPTION

The Rename command renames the specified file, folder, or disk to newName. If newName already exists, its previous contents are erased. To guard against inadvertent erasures, a dialog box requests confirmation before overwriting an existing file or folder. You can use the -c, -n, or -y options in scripts to handle this request noninteractively.

Note
You cannot use Rename to move a file to a different directory. To do this, use the Move command. •

Note
You cannot use wildcard characters in the following manner:

Rename ≈.text ≈.p

because the MPW Shell expands the filename patterns "≈.text" and "≈.p" before invoking Rename. To gain the desired effect, you need to execute a command like the one shown in the last example in the Examples section. •

INPUT

None

OUTPUT

None

ALIAS RESOLUTION

This command does not resolve leaf aliases in the original oldName parameter. If a path for a Finder alias file is specified, the Finder alias file is renamed. Embedded aliases in pathnames are resolved in the oldName and newName parameters. You can override this default behavior by using the -resolve option to force Rename to resolve leaf aliases.

STATUS

Rename can return the following status codes:

0

no errors

1

syntax error

2

oldName does not exist

3

execution error

4

Cancel selected or implied (-c)

PARAMETERS

oldName

Specifies a file, folder, or disk to be renamed.

newName

Specifies the new name.

OPTIONS

-c

Prevents the display of any confirmation dialog boxes by automatically responding Cancel. This causes Rename to abort before overwriting newName.

-n

Prevents the display of any confirmation dialog boxes by automatically responding No. This causes Rename to stop before overwriting newName.

-resolve

Forces resolution of leaf aliases in a pathname. If oldName specifies a Finder alias file and you specify -resolve, the target file or folder is renamed. Note that the pathname must be the same for both oldName and newName. When you use this option, the Finder alias file specified in the oldName parameter keeps its original name.

-y

Prevents the display of any confirmation dialog boxes by automatically responding Yes. This causes Rename to overwrite newName (deleting its current contents).

EXAMPLES

The following command line changes the name of File1 to File2. If File2 already exists, the Rename command is canceled and a status code of 4 is returned.

Rename File1 File2 -c

The next command line changes the name of Prog.c in the directory HD:Programs to Prog.Backup.c in the same directory:

Rename HD:Programs:Prog.c Prog.Backup.c

Assuming that Untitled is the name of a disk, the following command line changes the disk name to Backup :

Rename Untitled: Backup:

To perform a wildcard rename (as discussed in the second Note under Description), you can use the following For loop:

For Name In ≈.text
  (Evaluate "{Name}" =~ /(≈)®1.text/ ) > Dev:Null
  Rename "{Name}" "{®1}.p"
End

In this loop, Evaluate is executed only for its side effect of permitting regular expression processing. (The expression operator =~ indicates that the right side of the expression is a regular expression.) This allows you to use the regular expression capture mechanism, (regularExprn. Note that because the Evaluate command's output is unnecessary, it is thrown away (by redirecting it to the null device).

SEE ALSO

Move

 
 


Last Updated July 2000