Updated 2011-07-03 10:34:47 by dkf
file delete ?-force? ?--? pathname ?pathname ...?

Removes the file or directory specified by each pathname argument. Non-empty directories will be removed only if the -force option is specified. When operating on symbolic links, the links themselves will be deleted, not the objects they point to. Trying to delete a non-existent file is not considered an error. Trying to delete a read-only file will cause the file to be deleted, even if the -force flags is not specified. If the -force option is specified on a directory, Tcl will attempt both to change permissions and move the current directory 'pwd' out of the given path if that is necessary to allow the deletion to proceed. Arguments are processed in the order specified, halting at the first error, if any. A -- marks the end of switches; the argument following the -- will be treated as a pathname even if it starts with a -.

Note that to use file delete and glob, you need to do:
 eval file delete [glob -dir $dir *.orig]

for example. The eval is required to 'flatten' the list that glob returns. Or, if you use Tcl 8.5+, you may write:
 file delete {*}[glob -dir $dir *.orig]

(see {*} for an explanation).

Note that with tip 323 ([1]: Do nothing gracefully), file delete will accept to be called without pathname arguments, so then the above should be written as
  file delete {*}[glob -nocomplain -dir $dir *.orig]

to avoid errors when no file matches the pattern.

Also, note that
 file delete $pathname

only deletes a directory if it is empty. However
 file delete -force -- $pathname

will delete the directory, and everything under it, regardless. It is the functional equivalent of saying
 rm -rf $pathname

on Unix.

See also edit

[Category Tcl syntax help]Category Command