[macvoiceover] Re: Folders

Here's a perl program that will do that. it will even speak the number of directories and the number of files. take the code below and save it to a file. make the file executable in the terminal like this: chmod 775 /path/to/perlcount.pl then run it like this: /path/to/ perlcount.pl /path/to/directory

This whole thing could be done from the command line like this: ls - tl /path/to/directory | grep -c '^d'

The code below just makes this all nice and tidy with error checking.

Below is the perl code itself along with some comments, line preceded by #:



#!/usr/bin/perl
#

$testdir = $ARGV[0]; # put the first argument into the $testdir varriable this is the path to your directory.
#let's make sure the path given is a directory and not a file.
if (-d $testdir) {
#It's a directory so let's count the number of ls entries that start with d and put that number in to $dircount.
        $dircount = `ls -tl $testdir | grep -c '^d'`;
        #display the number.
        print "Number of directories: $dircount\n";
        #speak the number.
        `say "Number of directories:$dircount."`;
} else {
        #the path didn't exist or was a file so we tell the user.
        print "Please use a path to a directory.\n";
        `say "Please use a path to a directory."`;
}       
#----END OF CODE----

On Jul 27, 2007, at 13:49 , Richard Most wrote:

Howdy all,
Is there a way to find out the number of folders in a folder without opening the target folder?
Thanks for any help.

Richard Most
louie@xxxxxxxxxxxxxxxxx





Click on the link below to go to our homepage.
http://www.icanworkthisthing.com

Manage your subscription by using the web interface on the link below.
http://www.freelists.org/list/macvoiceover

Users can subscribe to this list by sending email to macvoiceover-request@xxxxxxxxxxxxx with 'subscribe' in the Subject field OR by logging into the Web interface at http://www.freelists.org/list/macvoiceover

Other related posts: