Forum Discussion
Altera_Forum
Honored Contributor
15 years agoTcl has some direct commands for finding file names, stripping the prefix off, etc. (I don't remember the names though.) When writing out a file, I always use the following, which looks to see if the file exists, copies it to a .bak file, and then opens a new one. (The file used here was a .csf)
set filename src if {[file exists $filename.csf]} { if {[file exists $filenam.csf.bak]} { puts "removing $filenam.csf.bak" file delete $filename.csf.bak } file copy $filename.csf $filename.csf.bak puts "moving $filename.csf to $filename.csf.bak" file delete $filename.csf } set file [file open $filename.csf a] puts $file "Add some text to the file" puts $file "Add some more" close $file