'\" 
'\" Copyright (c) 2001 by Andreas Kupries <a.kupries@westend.com>
'\" All rights reserved.
'\" 
'\" RCS: @(#) $Id: fileutil.n,v 1.7 2002/01/18 20:51:15 andreas_kupries Exp $
'\" 
.so man.macros
.TH fileutil n 1.1 Fileutil "file utilities"
.BS
'\" Note: do not modify the .SH NAME line immediately below!
.SH NAME
::fileutil \- Procedures implementing some file utilities
.SH SYNOPSIS
\fBpackage require Tcl 8\fR
.sp
\fBpackage require fileutil ?1.3?\fR
.sp
\fB::fileutil::cat\fR \fIfilename\fR
.sp
\fB::fileutil::find\fR ?\fIbasedir\fR ?\fIfiltercmd\fR??
.sp
\fB::fileutil::findByPattern\fR \fIbasedir\fR ?\fI-regexp\fI|\fI-glob\fR? ?\fI\--\fR? \fIpatterns\fR
.sp
\fB::fileutil::foreachLine\fR \fIvar filename cmd\fR
.sp
\fB::fileutil::grep\fR \fIpattern\fR ?\fIfiles\fR?
.sp
\fB::fileutil::touch\fR ?\fI-a\fR? ?\fI-c\fR? ?\fI-m\fR? ?\fI-r ref_file\fR? ?\fI-t time\fR? \fIfilename\fR ?\fI...\fR?
.BE
.SH DESCRIPTION
.PP
This package provides implementations of standard unix utilities
.TP
\fB::fileutil::cat\fR \fIfilename\fR
A tcl implementation of the UNIX "cat" command.  Returns the contents
of the specified file. The first argument is the name of the file to
read.
.TP
\fB::fileutil::find\fR ?\fIbasedir\fR ?\fIfiltercmd\fR??
An implementation of the unix command \fBfind\fR. Adapted from the
Tcler's Wiki. Takes at most two arguments, the path to the directory
to start searching from and a command to use to evaluate interest in
each file. The path defaults to \fB.\fR, i.e. the current
directory. The command defaults to the empty string, which means that
all files are of interest. The command takes care \fBnot\fR to loose
itself in infinite loops upon encountering circular link structures.
The result of the command is a list containing the paths to the
interesting files.
.TP
\fB::fileutil::findByPattern\fR \fIbasedir\fR ?\fI-regexp\fI|\fI-glob\fR? ?\fI\--\fR? \fIpatterns\fR
This command is based upon the TclX command \fBrecursive_glob\fR,
except that it doesn't allow recursion over more than one directory at
a time. It uses \fB::fileutil::find\fR internally and is thus able to
and does follow symbolic links, something the TclX command does not
do. First argument is the directory to start the search in, second
argument is a list of \fIpatterns\fR. The command returns a list of
all files reachable through \fIbasedir\fR whose names match at least
one of the patterns. The options before the pattern-list determine the
style of matching, either regexp or glob. glob-style matching is the
default if no options are given. Usage of the option \fI--\fR stops
option processing. This allows the use of a leading '-' in the
patterns.
.TP
\fB::fileutil::foreachLine\fR \fIvar filename cmd\fR
The command reads the file \fIfilename\fR and executes the script
\fIcmd\fR for every line in the file. During the execution of the
script the variable \fIvar\fR is set to the contents of the current
line. The return value of this command is the result of the last
invocation of the script \fIcmd\fR or the empty string if the file was
empty.
.TP
\fB::fileutil::grep\fR \fIpattern\fR ?\fIfiles\fR?
Implementation of grep. Adapted from the Tcler's Wiki. The first
argument defines the \fIpattern\fR to search for. This is followed by
a list of \fIfiles\fR to search through. The list is optional and
\fBstdin\fR will be used if is missing. The result of the procedures
is a list containing the matches. Each match is a single element of
the list and contains filename, number and contents of the matching
line, separated by a colons.
.TP
\fB::fileutil::touch\fR ?\fI-a\fR? ?\fI-c\fR? ?\fI-m\fR? ?\fI-r ref_file\fR? ?\fI-t time\fR? \fIfilename\fR ?\fI...\fR?
Implementation of touch. Alter the atime and mtime of the specified
files. If \fI-c\fR, do not create files if they do not already
exist. If \fI-r\fR, use the atime and mtime from \fIref_file\fR. If
\fI-t\fR, use the integer clock value \fItime\fR. It is illegal to 
specify both \fI-r\fR and \fI-t\fR. If \fI-a\fR, only change the 
atime. If \fI-m\fR, only change the mtime. 

.SH KEYWORDS
file utilities
