| Refresh | Home EGTry.com

traverse each file under a directory tree


filetree.pl

use strict;


dirTree("/tmp");
sub dirTree {
	  my $dirname=shift;
    local(*DIR);
    opendir(DIR, $dirname) || die "can not open $dirname ";
    while ( my $entry=readdir(DIR)) {
        my $path=$dirname . "/" . $entry;
        next if ($entry =~ /^\./); #exclude anything start with .
        if (-d $path) {
                dirTree($path);
                next;
        }
        doFile($path);
    }
    closedir(DIR);
}


sub doFile {
  my $filepath=shift;
  print "filepath: $filepath\n";
} 
       




output

filepath: /tmp/amf.data
filepath: /tmp/index.html
filepath: /tmp/output.data
filepath: /tmp/output.html
filepath: /tmp/remotingMessage.data
filepath: /tmp/req.data
filepath: /tmp/tmp.txt