Click here to get back home

Traverse a directory

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Traverse a directory weberw@adelphia.net 07-13-2006
Get Chitika Premium
Posted by weberw@adelphia.net on July 13, 2006, 2:10 pm
Please log in for more thread options


I want to print out a listing of folders and their contents with
indentation. I don't want to print folder 3.

Example of output.

Folder 1
a.xls
b.xls
Folder 2
c.xls
d.xls


Here is my code. I want to keep the formatting above. How do you do
this as well as exclude folder 3?
#!C://Perl/bin/perl
use CGI ':standard';
use CGI::Carp 'fatalsToBrowser';
#use strict;
use warnings;
use File::Find;
my $file_count = 0;
my $dir_count = 0;


$title = "Find Files";
print header,
        start_html($title),
        h1($title);
find ( {
wanted => \&wanted}, 'C:/Documents and
Settings/weberw/Desktop/test');

printf "\nThere are %d files in %d directories.\n",
$file_count,
$dir_count;

sub wanted {


        if (-d) {
return unless /[^.]/;
print "Directory Name is $File::Find::name\n";
print " \n";
$dir_count++;
}
elsif (-f _) {
print "File name is $File::Find::name\n";
$file_count++;
}
}




end_hmtl;


Posted by Gunnar Hjalmarsson on July 13, 2006, 3:36 pm
Please log in for more thread options


weberw@adelphia.net wrote:
> I want to print out a listing of folders and their contents ...

Please do not multi-post!

http://lipas.uwasa.fi/~ts/http/crospost.html

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Similar ThreadsPosted
New module XML::Traverse::ParseTree October 23, 2006, 5:57 pm
Glob and Traversing Directory July 14, 2006, 12:13 pm
New Script Directory needs your scripts listed September 3, 2005, 6:32 pm
Modules not installing to standard LIB directory November 17, 2005, 8:14 am
Current Directory when test.pl runs ? December 14, 2004, 9:31 am
CGI open of tmpfile: No such file or directory March 25, 2008, 6:00 am
Directory for site-packaged module man pages December 15, 2004, 2:55 pm
Loading Perl Modules from same directory as script February 13, 2006, 5:27 pm
Loading Perl Modules from same directory as script February 13, 2006, 5:35 pm
Net::Telnet => Will cd ( change directory ) command work ? February 27, 2006, 3:44 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap