niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » Perl » modules
Traverse a directory
Post new topic   Reply to topic Page 1 of 1 [1 Post] View previous topic :: View next topic
Author Message
weberw@adelphia.net
*nix forums beginner


Joined: 09 Jul 2006
Posts: 22

PostPosted: Thu Jul 13, 2006 6:10 pm    Post subject: Traverse a directory Reply with quote

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;
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [1 Post] View previous topic :: View next topic
The time now is Sun Nov 23, 2008 12:00 pm | All times are GMT
navigation Forum index » Programming » Perl » modules
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts change default install directory when using bdist_rpm krithika.sridhar@gmail.co python 1 Fri Jul 21, 2006 4:09 am
No new posts how to get perl to untar a tar.gz to a different directory Jack Perl 2 Fri Jul 21, 2006 12:40 am
No new posts /etc/postgresql/postgresql.env: No such file or directory Iuri Sampaio Debian 1 Wed Jul 19, 2006 8:40 pm
No new posts getting user's home directory on windows Sreeram Kandallu python 0 Tue Jul 18, 2006 3:33 pm
No new posts Apache on Windows with Active Directory Authentication Alvin Wong Apache 1 Tue Jul 18, 2006 7:05 am

Buy Playstation 3 | Western Union Money Transfer | Power Rangers | Consolidate Student Loans | France Hotels
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.2591s ][ Queries: 16 (0.1878s) ][ GZIP on - Debug on ]