Tcl File I/O Library Module

The Tcl file i/o library module has the file name fio.tcl. This module performs file input/output operations. File i/o is channel/stream oriented.

Here is a list of functions in the file i/o library module:

- unique
- exist
- numrecs
- get_nrec
- get_rec
- zcreate
- isdirectory
- filecopy
- qrename

# Module Dependencies

The following modules are required along with this module:

- parse.tcl

# Module Definition Files

This module requires the definition file:

- stdhead.tcl

# Module Procedures

## unique

    Declaration  : proc unique {dir fname}
    Parameters   :
          Name   : dir
          Type   : path string
    Description  : directory path

          Name   : fname
          Type   : file name string
    Description  : returned output file name

    Returns      : 1 upon success, 0 otherwise

This procedure will create a unique file name in the specified directory path. Note that the output file is not actually created. The returned output file name is created minus the directory path. Do not end the directory path with a path separator. The directory path may be an empty string (which will indicate the current directory).

The unique file name created will be in the form:

       11111111.tmp

Where 11111111 is a sequential number between one and 99,999,999

## exist

    Declaration  : proc exist {fname}
    Parameters   :
          Name   : fname
          Type   : string
    Description  : input file name

    Returns      : 1 if the file exists, 0 otherwise

This procedure will test for existence of a file.

## numrecs

    Declaration  : proc numrecs {fi}
    Parameters   :
          Name   : fi
          Type   : number
    Description  : input file channel

    Returns      : number of records/lines in the file, zero otherwise

This procedure will determine the number of lines/records in an ASCII file. Each line is assumed to be delimited by the appropriate line delimiter. The input file channel may be positioned to any part in the file as a seek to the beginning of the file is made prior to counting.

## get_nrec

    Declaration  : proc get_nrec {recno fi}
    Parameters   :
          Name   : recno
          Type   : number
    Description  : record/line number

          Name   : fi
          Type   : channel number
    Description  : input file channel

    Returns      : record contents upon success, empty string otherwise

Read and get a specific record/line number from the input file channel. The input file channel may be positioned to any part in the file as a seek call (to the beginning of the file) is made prior to counting.

## get_rec

    Declaration  : proc get_rec {fi}
    Parameters   :
          Name   : fi
          Type   : channel number
    Description  : input file channel

    Returns      : record contents upon success, empty string otherwise

Read and return the next record/line from the input file channel. The line delimiter is stripped from the line.

## zcreate

    Declaration  : proc zcreate {fname}
    Parameters   :
          Name   : fname
          Type   : file path/name string
    Description  : input file name

    Returns      : 1 upon success, 0 otherwise

This procedure will create a zero byte file. If the file does not exist, it will be created. It is an error if the file already exists.

## isdirectory

    Declaration  : proc isdirectory {path}
    Parameters   :
          Name   : path
          Type   : path string
    Description  : directory path

    Returns      : 1 if a directory, 0 otherwise

This procedure will determine whether the given directory path is actually a directory.

## filecopy

    Declaration  : proc filecopy {src dest}
    Parameters   :
          Name   : src
          Type   : path/file name string
    Description  : source path/name

          Name   : dest
          Type   : path/file name string
    Description  : destination path/name

    Returns      : 1 if the copy was successful, 0 otherwise

This procedure will copy a file from the source path/name to the destination path/name. If the destination path/name exists, it will be overwritten without warning.

## qrename

    Declaration  : proc qrename {src dest}
    Parameters   :
          Name   : src
          Type   : path/file name string
    Description  : source path/name

          Name   : dest
          Type   : path/file name string
    Description  : destination path/name

    Returns      : 1 if the rename was successful, 0 otherwise

Rename a file. A file may be renamed anywhere: same directory, different directory on same drive, different directory on different drive.

Goto Top | Tcl Applications | Tcl Software Overview | Tcl Library Overview
| Future Lab Home | Contact Webmaster | Feedback

Copyright © 2005-2006 Future Lab, Last Updated Jul 01, 2006