• Syntax and behavior are similar to the C I/O library
  • UNIX-like commands: cd, pwd
  • File handling: open, close
  • I/O : gets, puts
  • Information and misc: eof, file, glob
  • Pre-defined standard files: stdin, stdout, stderr
cd [dirName]
Usual UNIX syntax
Usual UNIX syntax
open fileName [accessType]
Opens the file named fileName
Returns a file identifier (the fileId of gets, puts,...)
accessType could be
Read Only. File must exist. Default.
Read and Write. File must exist.
Write Only. Truncates the file if already exists. Otherwise creates a new one.
Write and Read. Truncates if exists. Otherwise creates a new one.
Write only. Append if exists. Otherwise creates a new one.
Write and Read. Append if exists. Otherwise creates a new one.
% set fp [open $fname r]
close fileId
Close the file given by fileId and returns an empty string.
close $fp
gets fileId [varName]
Reads the next line from the file
Stores the line into varName
Returns the number of characters, or -1 for end of file (eof)
If varName is not provided, returns the line or an empty string for end of file
Removes the terminating newline
set fp [open $fname r]
while { [gets $fp line] >= 0 } {
    parse_line $line
gets stdin a                                ;# reads from stdin
puts [-nonewline] [fileId] string
Writes string into fileId
If fileId is not provided, stdout is assumed
Appends a newline unless the -nonewline option is used
Returns an empty string
eof fileId
Returns 1 if an end-of-file condition has occurred on fileId. 0 otherwise.
file { exists|rootname|dirname|tail|extension ...} args ...
A family of commands to get information about files and directories.
set setupName  setup.ini
if { [file exists $setupName] } {
    read_setup $setupName
set extension [file extension $setupName]        ;# gets ".ini"
glob [-nocomplain] [--] pattern [pattern ...]
Return a list of files that match any of the patterns
Uses glob pattern matching technique
If -nocomplain isn't specified, an error occurs if nothing matches
Use - to say that the next argument is the pattern (if it begins with a dash)
set DESIGN dummy
foreach sfx  { sp st* pa* lis tr* mt* ac* ma* sw* ms* } {
    foreach file [glob -nocomplain "$DESIGN.$sfx"] {
        VovInput $file