Created Tuesday 01 July 2014

File access

File commands

Make dir

Delete file/dir

Check if file exists

Check if dir exists

Copy file

Replace regexp

Replace in string

Replace a line in a file (+ set a timestamp)
set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
set filename "filename.txt"
set temp $$timestamp
set backup $filename.bak.$timestamp

set in [open $filename r]
set out [open $temp w]

# line-by-line, read the original file
while {[gets $in line] != -1} {
#transform $line somehow
set line [string tolower $line]

# then write the transformed line
puts $out $line

close $in
close $out

# move the new data to the proper filename
file link -hard $filename $backup
file rename -force $temp $filename