2014-11-17

TCL, File's Input & Output

[Procedure]
  • Open file --> Read/Write file --> Close file
[Syntax] 
  • Open ==> open filename "access"
  • Write ==> puts filename "content"
  • Close ==> close filename
[Example code]
  • set fd [open "$PATH/$var_sn.tmp.log" a] 
  • puts $fd "[time_str]: $msg"
  • close $fd
[Access Parameter List]
  • r : Reading a existing file
  • r+ : Reading & Writing a existing file
  • w : Empty a existing file,  and Writing the content.
  • w:  Establish a new file, and Writing the content.
  • w+ : Empty a existing file, and Writing & Reading the content.
  • w+ : Establish a new file, and Writing & Reading the content.
  • a : Append the content into the end of existing file, or Establish a new one.
  • a+ : Append (Read & Write) the content into the end of existing file, or Establish a new one.
End.

Example 2-:



Example 1-180515:
Copy from [SourceFile_content] to [TargetFile]

# set   sourceFile_tmp   [ open  SourceFile.tcl   r ]
# set   sourceFile           [ read   $sourceFile_tmp ]

# set   targetFile   [ open   TargetFile.tcl  w ]
# puts  $targetFile  $sourceFile


沒有留言:

張貼留言