Search code examples
tcldelete-filevivado

How to `rm -rf *` in TCL


I want to delete all files in a directory using TCL. (I'm using Xilinx Vivado's TCL console under Win 10.) I found that in TCL documentation that

file delete ?-force? ?- -? pathname ?pathname ... ?

should work. But

file delete -force -- [glob *]

does nothing. What's the wrong with that?


Solution

  • Make that

      file delete -force -- {*}[glob *]
    

    ... so that the path names returned by [glob] are turned into multiple arguments to [file delete] (using the expansion operator {*}), rather than one argument representing the one list of a path names (read by [file delete] as one, well complex file path).

    Alternatively, on Tcl older than 8.5, use an explicit loop:

     foreach path [glob *] {
        file delete -force -- $path
     }