file delete

Removes files and folders.

file delete ?-force? ?--? ?NAME ...?

Description

Removes each NAME. A NAME that does not exist is no error. A folder with content is an error, unless -force is there: then the folder goes away with all its content. With no NAME it removes no file.

Arguments

ArgumentTypeDefaultDescription
NAMEpathnoneA file or a folder to remove.

Options

OptionTypeDefaultSummary
-forceflagnoneRemoves a folder with all its content.
--flagnoneEnds the options.

-force

Removes a folder with all its content.

With -force a folder that has files goes away with each of them.

% file mkdir data2/sub
> file delete -force data2
> file exists data2
0

A flag has no value to check.

--

Ends the options.

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

% file delete -- -x

A flag has no value to check.

Returns

An empty string.

Examples

% set f [open n.txt w]; close $f
> file delete n.txt
> file exists n.txt
0

% file delete nope.txt

Errors

% file mkdir data/sub
> file delete data
error deleting "data": directory not empty
-errorcode POSIX EEXIST {file already exists}

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