Kimi
Kimi

Reputation: 43

TCL delete file

I use the below command to delete file in TCL. But it errors out, when the file does not exist.

Am I correct to say the "nocomplain" will prevent it from erroring out? If not, what options, can I use to stop it from error out when file does not exist?

eval file delete [glob nocomplain a.txt b.txt]

Upvotes: 0

Views: 5879

Answers (1)

Shawn
Shawn

Reputation: 52364

The documentation for file delete says:

Trying to delete a non-existent file is not considered an error.

So you can just use file delete a.txt b.txt. There's no need to use glob in your example because you don't have any wildcard patterns to match.

If you did, the documentation for glob describes the -nocomplain option to avoid raising an error if no files match. Note the leading dash.

Finally, you can use argument expansion instead of that ugly looking eval. Something like:

file delete {*}[glob -nocomplain a*.txt]

Upvotes: 2

Related Questions