Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
Python, Lua and Tcl - public course schedule [here]
Private courses on your site - see [here]
Please ask about maintenance training for Perl, PHP, Java, C, C++, Ruby, MySQL and Linux / Tomcat systems

Phone System reconfiguration 11.1.2018 to 26.1.2018 - we are on email but incoming landline not available. Temp number 0797 4 925928

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
4524Tcl - a new example for data reformatting
Tcl is an excellent language for combing through and reformatting data - though rarely a first choice language for such tasks if users aren't doing other things with it too. Towards the end of last week's Learning to program in TCL course, a "side task" requirement came up to reformat our course diary ...
4523Catching failed commands and not crashing the program in Tcl
Where a command may fail in Tcl (causing Tcl to crash), you can defer it within a catch command. That will return a true value if it fails, and an optional extra parameter gives you the associated error message. A program to look for the biggest file in or below a directory [here] fails if you run ...
4461Reading from a URL, and reading Json, from your Tcl script
You can read from a URL in Tcl using the http package ... for example   package require http   set handle [::http::geturl http://www.wellho.co.uk/robots.txt] And you can then collect the data:   set body [::http::data $handle] and the http status code:   set ...
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 ...
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 ...
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, ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
Examples from our training material
bigbelow   Find biggest file in or below a specified folder
bigbelow.v2   biggest below - practical example that traps empty folders
biggest   using glob to check all files in a directory
diary   diary data for for_qa script
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
for_qa.tcl   Data reformatting example / course end tie together
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
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 [here].
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.
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,Ruby, Lua, 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.

You can Add a comment or ranking to this page

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

PAGE: http://www.wellho.net/resources/T209.html • PAGE BUILT: Mon Feb 8 18:55:24 2016 • BUILD SYSTEM: WomanWithCat