Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: File::Find - Traverse the first level directories from starting point - How?

by Anonymous Monk
on May 19, 2020 at 12:36 UTC ( [id://11116940]=note: print w/replies, xml ) Need Help??


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

Maxdepth option controls it Or easier interface my @files = File::Find::Rule->file() ->name( '*.txt', '*.log' ) #can insert regex too ->maxdepth($level) ->in(@LogDirs);
  • Comment on Re: File::Find - Traverse the first level directories from starting point - How?

Replies are listed 'Best First'.
Re^2: File::Find - Traverse the first level directories from starting point - How?
by vskatusa (Acolyte) on May 19, 2020 at 15:09 UTC
    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.

      \\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.

      Hi, try adding a trailing slash?


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11116940]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-04-24 11:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found