Traverse a directory

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

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
Folder 2

Here is my code.  I want to keep the formatting above. How do you do
this as well as exclude folder 3?
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,
find ( {
  wanted => \&wanted}, 'C:/Documents and

printf "\nThere are %d files in %d directories.\n",

sub wanted {

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



Re: Traverse a directory wrote:
Quoted text here. Click to load it

Please do not multi-post!

Gunnar Hjalmarsson

Site Timeline