in reply to Read Directory
As wise Corion you are not checking the right thing:
you start the script in the directory /one then you open /one/two/three reading it. If you say cd four you'll go in /one/four not in /one/two/three/four
Take a read of Cwd
Tested:
#!usr/bin/perl # ADD THESE TWO LINES! use strict; use warnings; # so you are forced to declare variables with my my $path='/home/something/something/something'; opendir(DIR,$path) or die"couldnt open the directory\n"; # parens not needed # UPDATE: assignement to $_ is needed with older perls: nowadays while +(readdir DIR) will suffice # as choroba spotted it is since 5.12 that readdir automatically feeds + $_ # doc says: As of Perl 5.12 you can use a bare readdir in a while loop +, which will set $_ on every iteration. while($_ = readdir DIR) { # this is wrong! # if(-d BUS) if ($_ eq 'BUS' and -d $path.'/'.$_) #corrected by Corion { # append BUS to the path # infact you are not changing directory my $buspath = $path.'/'.$_; opendir(VEH, $buspath) or die"couldnt open the directory [$bus +path]\n"; while($_ = readdir VEH) { print "$_\n" if -f $buspath.'/'.$_; } } }
You can profit of Re: Win32 Recursive Directory Listing
L*
|
|---|