Version 11 of fileutil

Updated 2003-12-16 09:42:12

Documentation can be found at http://tcllib.sourceforge.net/doc/fileutil.html


Currently the fileutil package contains a find, grep, and cat . Other procs that would be useful to add would include wc, tee, head, tail, and perhaps some awk'ish type functions ala Tclx.

For more on grep, see "NR-grep: A Fast and Flexible Pattern Matching Tool" [L1 ].


Perhaps even some code like Glenn Jackman's:

    proc touch {filename {time ""}} {
        if {[string length $time] == 0} {set time [clock seconds]}
        file mtime $filename $time
        file atime $filename $time
    }

glennj: This proc has been accepted into tcllib 1.2: http://tcllib.sourceforge.net/doc/fileutil.html

US Unix-like touch:

    proc touch {filename {time ""}} {
        if {![file exists $filename]} {
           close [open $filename a]
           }
        if {[string length $time] == 0} {set time [clock seconds]}
        file mtime $filename $time
        file atime $filename $time
    }

What other file related procs would be useful?


2003-11-28 VI Nice of you to ask. There's a list above, other than that : tail -f, split, join. I use tkcon as my main shell on a wimpy laptop. fewer dlls loaded is good..


2003-12-16 SS Tring to improve over the Tcl implementation of wc in the Great Computer Shootout I wrote this, that seems half in execution time against big files:

 set text [read stdin]
 set c [string length $text]
 set l [expr {[llength [split $text "\n\r"]]-1}]
 set T [split $text "\n\r\t "]
 set w [expr {[llength $T]-[llength [lsearch -all -exact $T {}]]-1}]
 puts "\t$l\t$w\t$c"

Output seems to be identical to GNU's wc command.


Category Package, subset Tcllib