[opensuse-programming] find stop search criteria
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. Any ideas? -- Roger Oberholtzer -- To unsubscribe, e-mail: opensuse-programming+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-programming+owner@opensuse.org
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.
Any ideas?
Look at '-prune'. That ought to enable you to skip subdirs, at least. -- Per Jessen, Zürich (20.6°C) http://www.hostsuisse.com/ - virtual servers, made in Switzerland. -- To unsubscribe, e-mail: opensuse-programming+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-programming+owner@opensuse.org
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
On Sat, Sep 8, 2018 at 8:41 AM David Haller <dnh@opensuse.org> wrote:
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;
Thanks for that. And I could do the same thing in Tcl (my choice for this type of thing.). I was just curious about a pure command line option. I will try Per's -prune option later today. But I'm not sure how that works when you do not know the name or depth of the directory to skip. Only that a match is already found in the parent directory. So I may wind up fiddling with your script... -- Roger Oberholtzer -- To unsubscribe, e-mail: opensuse-programming+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-programming+owner@opensuse.org
participants (3)
-
David Haller
-
Per Jessen
-
Roger Oberholtzer