Version 2 of file delete

Updated 2003-10-03 00:46:30

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.

Also, note that

 file delete pathname

only deletes the 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:


Tcl syntax help - Category Command