Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
Python and Tcl - public course schedule [here]
Private courses on your site - see [here]
Please ask about maintenance training for Perl, PHP, Lua, etc
 
Searching 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 many) files. It's a neat and useful demosntration of an application which most people can identify with.

See examples in Ruby, Tcl and Perl.

The method used is to keep a queue of directories to be checked in a list / array, and travese them one at a time. As new directories are found, they're added onto the end of the list / array, and as each directory is traversed, it's removed from the array, And when the array is empty, the program is done.

It's been suggested to me that when a directory is found within another ditrectory, the traversing of the parent should be suspended while the child (and any children it has) are handled. That can be done neatly through recurrsion, but the code ends up being a bit too "clever" to be easy to follow and - unless you need to traverse in a certain order - it's unnecessary.
(written 2011-09-09)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
P602 - Perl - Advanced File and Directory Handling
  [3412] Handling binary data in Perl is easy! - (2011-08-30)
  [2876] Different perl examples - some corners I rarely explore - (2010-07-18)
  [1861] Reactive (dynamic) formatting in Perl - (2008-10-31)
  [1832] Processing all files in a directory - Perl - (2008-10-11)
  [1709] There is more that one way - Perl - (2008-07-14)
  [1225] Perl - functions for directory handling - (2007-06-09)
  [975] Answering ALL the delegate's Perl questions - (2006-12-09)
  [839] Reporting on the 10 largest files or 10 top scores - (2006-08-20)

R106 - Input and Output in Ruby
  [4678] Expect with Ruby - a training example to get you started - (2016-05-18)
  [4499] Significant work - beyond helloworld in Ruby - (2015-05-27)
  [2974] Formatting your output - options available in Ruby - (2010-09-29)
  [2893] Exclamation marks and question marks on ruby method names - (2010-07-28)
  [2621] Ruby collections and strings - some new examples - (2010-02-03)
  [2614] Neatly formatting results into a table - (2010-02-01)
  [2290] Opening and reading files - the ruby fundamentals - (2009-07-16)
  [1887] Ruby Programming Course - Saturday and Sunday - (2008-11-16)
  [1587] Some Ruby programming examples from our course - (2008-03-21)

T209 - Tcl/Tk - File and Directory Handling
  [4524] Tcl - a new example for data reformatting - (2015-10-10)
  [4523] Catching failed commands and not crashing the program in Tcl - (2015-10-10)
  [4461] Reading from a URL, and reading Json, from your Tcl script - (2015-03-12)
  [3617] The fileutil package and a list of file system commands in Tcl - (2012-02-18)
  [3320] Reading the nth line from a file (Perl and Tcl examples) - (2011-06-09)
  [3192] Tcl - Some example of HOW TO in handling data files and formats - (2011-03-04)
  [2467] Tcl - catching an error before your program crashes - (2009-10-22)
  [1467] stdout v stderr (Tcl, Perl, Shell) - (2007-12-10)
  [1426] Buffering up in Tcl - the empty coke can comparison - (2007-11-10)
  [1407] Reading from another process in Tcl (pipes and sockets) - (2007-10-26)
  [785] Running external processes in Tcl and Tcl/Tk - (2006-06-29)
  [779] The fragility of pancakes - and better structures - (2006-06-26)


Back to
How many days to Christmas?
Previous and next
or
Horse's mouth home
Forward to
Sigils - the characters on the start of variable names in Perl, Ruby and Fortran
Some other Articles
Exceptions - a fail-safe way of trapping things that may go wrong
3 digit HTTP status codes - what are they, which are most common, which should be a concern?
Ruby at both extremes of your website
Sigils - the characters on the start of variable names in Perl, Ruby and Fortran
Searching through all the files in or below a directory - Ruby, Tcl, Perl
How many days to Christmas?
What is on the Melksham Agenda?
Automed web site testing scripted in Ruby using watir-webdriver
Our National Autograss Champion, from Melksham
Divide 10000 by 17. Do you get 588.235294117647, 588.24 or 588? - Ruby and PHP
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2019: 404 The Spa • Melksham, Wiltshire • United Kingdom • SN12 6QL
PH: 01225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/3429_Sea ... -Perl.html • PAGE BUILT: Sat May 27 16:49:10 2017 • BUILD SYSTEM: WomanWithCat