I am running the following:
#!/usr/bin/perl; use strict; sub readindirs { my ($dirname) = @_; print "$dirname -> dirname \n"; opendir(NEWDIR, $dirname) or die $!; my @newfiles = grep { $_ ne '.' and $_ ne '..' } readdir NEWDIR; closedir NEWDIR; foreach my $name (@newfiles) { if (-d $name) { print "name:: $name \n"; readindirs($name); } else { print "parse file : $name \n"; #&parse_file($name); } } } &readindirs('.');
Which results in this:
Of which contact, coredocs, organization, overview, and programs are directories.. -> dirname name:: about about -> dirname parse file : aic3.pl parse file : contact parse file : coredocs parse file : footer.inc parse file : index.html parse file : nav.js parse file : organization parse file : overview parse file : programs parse file : rightnav.inc parse file : template.html parse file : top.inc parse file : about2.zip parse file : aic.pl parse file : aictemp.pl
I am doing this on a windows distr. and am not really a windows person, I know that there are a few differences between *nix and windows perl, is this one of them? The other thing, which is purely for my own interest, is how is if (-d $name) better/worse than (opendir(DIR, $name)).
Thanks a lot for your help. If I can't figure it out soon, I think that I will go to the modules.
In reply to Re: Re: Navigating Dierctories Recursively
by cens
in thread Navigating Dierctories Recursively
by cens
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |