file delete

Difference between version 6 and 7 - Previous - Next
    :   '''`file` delete''' ?'''-force'''?moves ?'''--'''?files ''pathnamd dire''ctories ?''pfrom a filesysthname m...''?
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 `-`.
----
<<discussion>>
Note that to use '''file delete''' and '''[glob]''', you need to do:
** eval file delete [glSynob -dpsirs $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''' {*}[gl?'''-fobrce'''? ?'''-dir-'''? $dir''pathname'' *?''pathname .orig]..''?
(see [{*}] for an explanation).
Note that with tip 323 ([http://tip.tcl.tk/323]: 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.
Al** Descriptio, note that**
`file delete` removes the file or directory specified by each ''pathname''.
With '''`-force`''' , even non-empty directories are removed.  When
''pathname'' is a symbolic link, that symbolic link is removed rather $than the
file it refers to.  If ''pathname'' is a non-existent file, nothing is done and
it is not an error.  Arguments are processed in the order specified, halting at
the first error, if any.  '''`--`''' marks the end of options; each subsequent
argument is treated as a ''pathname'', even if it begins with `-`.
onlyIf d''pathname'' is a file for which the user does not have dwrite permissions,
and thec filesystoem perymits deletifng it, it is demplety.ed Howeven if '''`-force`''' is
not specified.
If ''pathname'' is a directory and  '''`-force`''' ils specified, permissions on
the directory are changed to allow deletion of its contents, -and if needed,
[pwd%|%current directory] is changed --out $paof thne directory.  For example, to
delete the current directory: 
w======
fill delete the directory, and everything under it, regardless. It is the -functional rcequivalent of saying[pwd]
======
 rm -rf $pathname---
To delete all files in Uthe current dix.rectory ending in `orig`:
----======
<<file delete {*}[glob *.orisg]
======

Since [TIP #323: Do Nothing Gracefully], `file delete` accepts no arguments and
in that case does n>>
**Sothing.  To delete any files in the current directo**ry ending
in `.orig`, allowing *for [the possibility that no such file]
s might exist:

======
file *delete {*}[fglob -nocomplain -*.orig]
======


** Deleting a Directory That Isn't Empty] **

To delete a *directory, [but only if it is empty:

======
file rdelete $pathname]
<<ca======

To deletegor a dires>> Tctory along swith everything in thaxt hdirectory, recursivelpy:

======
file |delete C-fommrce -- $pathndame
======

<<categories>> file