Hello, On Mon, 03 Sep 2018, Roger Oberholtzer wrote:
I want to use find to locate files with a specific suffix. The thing is that once I find a file with that suffix, I do not want to continue in that directory or it's sub-directories - especially not any sub-directories. But I do want the search to otherwise continue.
I have seen how to get find to stop after X matches. But that is not what I need. The sub-directories contain 10s of thousands of images. When run over a network, skipping these speed things tremendously.
==== #!/usr/bin/perl -w use strict; use File::Find; my $pat = qr/\.jpg$/; sub preprocess { my @found = grep { /$pat/i ; } @_ ; if( ! scalar @found ) { return grep { -d $_ } @_; } else { return $found[0]; ### first match on $pat only #return @found; ### all matches on $pat } } sub wanted { if( -f _ && /$pat/si ) { printf("dir=%s, name=%s, _=%s\n", $File::Find::dir, $File::Find::name, $_); $File::Find::prune = 1; return; } } find({ wanted => \&wanted, preprocess => \&preprocess }, @ARGV); ==== This seems to work rather efficiently. Implementing what to print or otherwise react and making the pattern and "ignore case" to be settable via an option is left as an exercise for the reader ;) HTH, -dnh PS: I started with: find2perl . -type f -iname '*.jpg --
Überredet - brauch' meine tägliche Dosis suse-talk. <zur Gruppe umdreh> Jungs, wir haben sie festgenagelt! Die ist süchtig nach uns ... <zufrieden grins> [Moss und Helga Fischer in suse-talk] -- To unsubscribe, e-mail: opensuse-programming+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-programming+owner@opensuse.org