file rename

Moves or renames files and folders.

file rename ?-force? ?--? SOURCE TARGET
file rename ?-force? ?--? SOURCE ?SOURCE ...? DIR

Description

Moves SOURCE to TARGET, with the rules of file copy for a folder as TARGET, more than one SOURCE, -force, and --. The SOURCE is gone after the move.

Arguments

ArgumentTypeDefaultDescription
SOURCEpathrequiredA file or a folder to move.
TARGETpathrequiredThe new path, or a folder for the moved files.

Options

OptionTypeDefaultSummary
-forceflagnoneReplaces a target that exists.
--flagnoneEnds the options.

-force

Replaces a target that exists.

With -force a TARGET that exists is replaced.

% set f [open r1 w]; close $f
> set f [open r2 w]; close $f
> file rename -force r1 r2
> file exists r1
0
% file rename -force
wrong # args: should be "file rename ?-option value ...? source ?source ...? target"
-errorcode NONE

--

Ends the options.

The next argument is a SOURCE, also when it starts with -.

% set f [open -r w]; close $f
> file rename -- -r r
> file exists r
1

A flag has no value to check.

Returns

An empty string.

Examples

% set f [open m.txt w]; close $f
> file rename m.txt k.txt
> list [file exists m.txt] [file exists k.txt]
0 1

% set f [open s1 w]; close $f
> file mkdir dd
> file rename s1 dd
> file exists dd/s1
1

Errors

% file rename nope.txt z.txt
error renaming "nope.txt": no such file or directory
-errorcode POSIX ENOENT {no such file or directory}

% file rename a
wrong # args: should be "file rename ?-option value ...? source ?source ...? target"
-errorcode NONE

Facts

Capability
file. A new interpreter does not have it until the host turns it on.
Tcl release
Tcl 9.1 and 8.6.
Since
ztcl 1.0.0-beta.1

See also