Version 1 of Additional file commands

Updated 2001-12-17 09:35:37

Read a text file into a string:

 proc readfile filename {
    set fp [open $filename]
    set res [read $fp [file size $filename]]
    close $fp
    set res 
 }

Touch a file: without modifying the contents, change a file's access time to (now); create it if it doesn't exist, with 0 bytes contents:

 proc touch filename {
    close [open $filename a]
 } ;# after Don Porter in c.l.t, brought here by RS 

file - Arts and crafts of Tcl-Tk programming