Traversing folders

Discussion in 'Perl Misc' started by Dirk, Jul 11, 2012.

  1. Dirk

    Dirk Guest

    Hi,

    I am new to Perl and I am trying to list all the folders within a given folder and I have the following code. I know it is simple but for some reason the program just stops and I am not seeing any error code being returned.

    Does anybody have a good example of File::Find that they are willing to share. Examples are easier for me to follow.


    #!/usr/bin/perl
    #

    use warnings;
    use strict;
    use File::Find;

    my $path_name;
    $path_name = '/test';

    find sub {
    return unless -d;
    print "$File::Find::name\n";
    },$path_name;

    exit;
    Dirk, Jul 11, 2012
    #1
    1. Advertising

  2. Dirk <> writes:
    > I am new to Perl and I am trying to list all the folders within a
    > given folder and I have the following code. I know it is simple but
    > for some reason the program just stops and I am not seeing any error
    > code being returned.


    [...]

    > #!/usr/bin/perl
    > #
    >
    > use warnings;
    > use strict;
    > use File::Find;
    >
    > my $path_name;
    > $path_name = '/test';
    >
    > find sub {
    > return unless -d;
    > print "$File::Find::name\n";
    > },$path_name;
    >
    > exit;


    Works for me.
    Rainer Weikusat, Jul 11, 2012
    #2
    1. Advertising

  3. Dirk

    Hans Mulder Guest

    On 11/07/12 17:40:59, Dirk wrote:
    > Hi,
    >
    > I am new to Perl and I am trying to list all the folders within a given
    > folder and I have the following code. I know it is simple but for some
    > reason the program just stops and I am not seeing any error code being
    > returned.
    >
    > #!/usr/bin/perl
    > #
    >
    > use warnings;
    > use strict;
    > use File::Find;
    >
    > my $path_name;
    > $path_name = '/test';
    >
    > find sub {
    > return unless -d;
    > print "$File::Find::name\n";
    > },$path_name;
    >
    > exit;


    Does '/test' exist on your system?

    What happens if you try $path_name = '..'; ?

    -- HansM
    Hans Mulder, Jul 12, 2012
    #3
  4. Ben Morrow <> writes:
    > Quoth Dirk <>:


    [...]

    >> #!/usr/bin/perl
    >> #
    >>
    >> use warnings;
    >> use strict;
    >> use File::Find;
    >>
    >> my $path_name;
    >> $path_name = '/test';
    >>
    >> find sub {
    >> return unless -d;
    >> print "$File::Find::name\n";
    >> },$path_name;
    >>
    >> exit;

    >
    > You don't need to call 'exit' unless you want to exit early, or with an
    > error code. Falling off the end of a Perl program is the usual way to
    > exit successfully.


    JFTR: This is not necessarily always true. For instance, the embedded
    perl interpreter Nagios may use for executing plugins written in Perl
    complains about plugins which didn't exit 'properly' if there is no
    explicit exit statement at the end of the code.
    Rainer Weikusat, Jul 12, 2012
    #4
  5. Dirk

    Dirk Guest

    Thanks to everybody for their input. When I first ran the code I was running it for a folder that did not have a lot of sub-folders. When I ran it agains a very large folder I could not verify all folders and it appeared thatI had some missing folders. After being able to verify all the folders andit appears that the code did return all sub-folders.

    However, I did notice that I am getting a permission error. Something aboutnot being able to change directory.

    Thanks again for all the replies.
    Dirk, Jul 13, 2012
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. steven
    Replies:
    6
    Views:
    908
    steven
    Aug 27, 2003
  2. Asad

    XML - traversing in VB

    Asad, Apr 16, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    582
    Matt Berther
    Apr 16, 2004
  3. Replies:
    4
    Views:
    674
  4. =?Utf-8?B?c2xpbV9uYWxkeQ==?=

    traversing a client directory in ASP.NET

    =?Utf-8?B?c2xpbV9uYWxkeQ==?=, May 10, 2005, in forum: ASP .Net
    Replies:
    10
    Views:
    814
    Scott M.
    May 12, 2005
  5. thomson
    Replies:
    0
    Views:
    320
    thomson
    Dec 27, 2005
Loading...

Share This Page