Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact

Well House Consultants
You are on the site of Well House Consultants who provide Open Source Training Courses and business hotel accommodation. You are welcome to browse and use our resources subject to our copyright statement and to add in links from your pages to ours.
Other subject areas - resources
Java Resources
Well House Manor Resources
Perl Resources
Python Resources
PHP Resources
Object Orientation and General topics
MySQL Resources
Linux / LAMP / Tomcat Resources
Well House Consultants Resources
Extras Resources
C and C++ Resources
Ruby Resources
Tcl/Tk Resources
Web and Intranet Resources
Tcl/Tk module T209
File and Directory Handling
Exercises, examples and other material relating to training module T209. This topic is presented on public courses Learning to program in Tcl, Tcl Programming, Tcl Programming

This module covers opening, reading and writing files in Tcl. You'll also learn how to check the contents of directories, test for the existence of individual files, and look up other information ranging from file size to file update time.


Articles and tips on this subjectupdated
3617The fileutil package and a list of file system commands in Tcl
On top of the file commands, the ::fileutil package which is shipped with Tcl includes a range of commonly used structures ("design patterns") which means you don't have to keep wring your own composites. Here is a combined list, sorting them out by category rather than by which command or package they ...
2012-02-18
 
3429Searching through all the files in or below a directory - Ruby, Tcl, Perl
Many of our customers want to learn how to traverse all the files in a directory, or perhaps even all the files in or below a directory. I quite often write a demonstration program during our courses which looks though part of a file system tree for files over a certain size, or for the largest (so ...
2011-09-09
 
3320Reading the nth line from a file (Perl and Tcl examples)
"How do I find the 100th line in a file" - a common question for newcomers to coding. The short answer is to open the file, and loop through to read lines until the one that you want. Although most languages have a seek command or function, that works by bytes and with a typical text / ascii file, ...
2011-06-09
 
3192Tcl - Some example of HOW TO in handling data files and formats
During the Tcl course I was running earlier this week, we got involved in a number of interesting topics such as • How to clean up input lines into lists of fields (use split) • How to reformat awkward fields (use regexp and regsub) • How to combine files that vary in format from year ...
2011-03-04
 
1407Reading from another process in Tcl (pipes and sockets)
If you want to read from another process on the same system that you're running your code on in Tcl can be done using a pipe - you can use open with the command name instead of the file name, preceeded by a pipe character (|) - thus: set said [open |df r]   while {[gets $said this] >= 0} {   puts ...
2011-03-01
 
2467Tcl - catching an error before your program crashes
There are times when a Tcl command can fail because of the data being passed in to it ... and when it fails, it can do so with a spectacular crash! For example, the glob command which matches files to a pattern (Tcl's ls or dir if you like to think of it that way) can go 'belly up' if there are no files ...
2009-10-22
 
1467stdout v stderr (Tcl, Perl, Shell)
When you're programming, you shouldn't write code to read directly from the keyboard and write to the screen .... what if you want to have your program read from or write to a file sometimes? Instead, you should write code to read from stdin (Tcl) or STDIN (Perl) and write to stdout (Tcl) or STDOUT ...
2007-12-12
 
1426Buffering up in Tcl - the empty coke can comparison
A comment on buffering in Tcl .... if {1 == 0} { When you finish drinking a can of Coke, you don't call your local recycling plant up straight away and have them send a truck around to collect the empty - that would be inefficient to put it mildly. And in the same way, a computer doesn't always save ...
2007-11-10
 
779The fragility of pancakes - and better structures
Have you ever hunted around a directory for a file ... you KNOW it's there, but you can't find it - can't see the wood for the trees, if you like, in a listing that spills over many pages? I call such directory structures "pancakes" as they're thin and flat, and they tend not to be very easy to work ...
2006-06-30
 
785Running external processes in Tcl and Tcl/Tk
If you want to run external processes from a Tcl based program (Tcl, Tcl/Tk, expect), there are various ways of doing it. Firstly, the whole purpose of the Expect extension is to allow you to control other processes via its three major commands of spawn which starts another process, send which sends ...
2006-06-30
 
Examples from our training material
bigbelow   Find biggest file in or below a specified folder
biggest   using glob to check all files in a directory
disc_status   Piping input from an operating system command
dnstab   Read a file, extract from it
failer   Using catch to trap file open failures
files   fileutil package in use
filework   Report file statuses
multifile   Output to stdout and several files at the same time
rail   Data extraction and reporting from multiple files
recent   List all files modified in the last hour
Pictures
Tcl is a great Engineer's language
Background information
Some modules are available for download as a sample of our material or under an Open Training Notes License for free download from http://www.training-notes.co.uk.
Topics covered in this module
Reading and writing files.
Opening a file - the basics.
Reading from a file.
Writing to a file.
Closing a file.
More about reading and writing files.
Other open access arguments.
An alternative to gets.
Other Input/Output commands.
Example.
File and directory handling.
The file command.
Looping through all the files in a directory.
Complete learning
If you are looking for a complete course and not just a information on a single subject, visit our Listing and schedule page.

Well House Consultants specialise in training courses in Tcl/Tk, Expect,Python, Perl, PHP, and MySQL. We run Private Courses throughout the UK (and beyond for longer courses), and Public Courses at our training centre in Melksham, Wiltshire, England. It's surprisingly cost effective to come on our public courses - even if you live in a different country or continent to us.

We have a technical library of over 700 books on the subjects on which we teach. These books are available for reference at our training centre. Also available is the Opentalk Forum for discussion of technical questions.


You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2014: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/resources/T209.html • PAGE BUILT: Thu Sep 18 11:03:17 2014 • BUILD SYSTEM: WomanWithCat