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?

The following code works
use Path::Tiny; my $dir = '//192.168.1.44/somedir'; my @files = path( $dir )->children( qr/\.txt\z/ ); #Excludes "." and " +.." automatically. my @myDirectories = path( $dir )->children; for my $dirName ( @myDirectories ){ print "$dirName\n"; }
However if I change the $dir as follows it does not work (I am aware technically //192.168.1.44 is not a directory but a share)
use Path::Tiny; my $dir = '//192.168.1.44'; # traverse root my @files = path( $dir )->children( qr/\.txt\z/ ); #Excludes "." and " +.." automatically. my @myDirectories = path( $dir )->children; for my $dirName ( @myDirectories ){ print "$dirName\n"; }
I get the following error when running the above code
Error opendir on '//192.168.1.44': Invalid argument at dir.pl line 44.

Replies are listed 'Best First'.
Re^3: File::Find - Traverse the first level directories from starting point - How?
by ikegami (Patriarch) on May 20, 2020 at 20:14 UTC

    \\server\share is the root of the volume. You can't list the contents of the directory \\server because \\server isn't a directory. This has nothing to do with Perl.

    >dir /b \\127.0.0.1 The filename, directory name, or volume label syntax is incorrect. >dir /b \\127.0.0.1\SomeShare a.txt b.txt

    This might be useful.

Re^3: File::Find - Traverse the first level directories from starting point - How?
by 1nickt (Canon) on May 20, 2020 at 04:04 UTC

    Hi, try adding a trailing slash?


    The way forward always starts with a minimal test.
      Tried trailing slash but no luck. Any other suggestions?