Hello,

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*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

In reply to Re: Read Directory by Discipulus
in thread Read Directory by Nansh

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.