in reply to Re: File::Find - Traverse the first level directories from starting point - How?
in thread File::Find - Traverse the first level directories from starting point - How?

Thank you very much. For the benefit of others here is the code that worked.
use Path::Tiny qw/ path cwd /; my $dir = '//192.168.1.44/somedir'; my @files = path( $dir )->children; my @myDirectories = path( $dir )->children; for my $dirName ( @myDirectories ){ if (!( $dirName =~ m/\/\./ )) { # skip dir like /xxxx/.xx print "$dirName\n"; } }
  • Comment on [Soved] Re^2: File::Find - Traverse the first level directories from starting point - How?
  • Download Code

Replies are listed 'Best First'.
Re: [Soved] Re^2: File::Find - Traverse the first level directories from starting point - How?
by 1nickt (Canon) on May 19, 2020 at 05:47 UTC

    Great, thanks for the feedback!

    A slightly more idiomatic way of writing your code:

    use strict; use warnings; use Path::Tiny; my $dir = '//192.168.1.44/somedir'; path( $dir )->visit( sub { print "$_\n" if /^[^.]/ && $_->is_dir; });

    Note that your code reads the names of all the files (plain files and directories) into two different variables; also I'm not sure about the regexp, it's not clear from your comment what names you are wanting to skip. The file/dir name at that point in the loop shouldn't have a leading slash IIUC.

    Hope this helps!

    Update: s/all the files/names of all the files/ thx soonix

    The way forward always starts with a minimal test.