| 1 |
joko |
1.1 |
#!/usr/bin/perl |
| 2 |
|
|
|
| 3 |
|
|
## ------------------------------------------------------------------------ |
| 4 |
joko |
1.3 |
## $Id: finder.pl,v 1.2 2003/02/01 02:52:32 joko Exp $ |
| 5 |
joko |
1.1 |
## ------------------------------------------------------------------------ |
| 6 |
joko |
1.2 |
## $Log: finder.pl,v $ |
| 7 |
joko |
1.3 |
## Revision 1.2 2003/02/01 02:52:32 joko |
| 8 |
|
|
## + minor update |
| 9 |
|
|
## |
| 10 |
joko |
1.2 |
## Revision 1.1 2003/02/01 01:38:35 joko |
| 11 |
|
|
## + initial commit - partly refactored from replace_cvs.pl |
| 12 |
|
|
## |
| 13 |
joko |
1.1 |
## ------------------------------------------------------------------------ |
| 14 |
|
|
|
| 15 |
|
|
|
| 16 |
|
|
=pod |
| 17 |
|
|
|
| 18 |
|
|
finder.pl - find things (files) and print their names on STDOUT |
| 19 |
|
|
|
| 20 |
|
|
- finder.pl |
| 21 |
|
|
finds all files/directories in current path |
| 22 |
|
|
|
| 23 |
|
|
- finder.pl . |
| 24 |
|
|
finds all files/directories in current path (again) |
| 25 |
|
|
|
| 26 |
|
|
- finder.pl --regex=test |
| 27 |
|
|
finds all files/directories matching 'regex' in current path |
| 28 |
|
|
|
| 29 |
|
|
- finder.pl --regex=/CVS/Root$ /tmp/cvsroot |
| 30 |
|
|
finds all files/directories matching 'regex' in path '/tmp/cvsroot' and below (recursively) |
| 31 |
|
|
|
| 32 |
joko |
1.3 |
- todo: |
| 33 |
|
|
x exclude mechanism (use regex-exclude) |
| 34 |
|
|
o remember all matched entries while processing, show at end of processing in report |
| 35 |
|
|
o add some statistics (count-matched/count-all) |
| 36 |
|
|
|
| 37 |
joko |
1.1 |
=cut |
| 38 |
|
|
|
| 39 |
|
|
|
| 40 |
|
|
use strict; |
| 41 |
|
|
use warnings; |
| 42 |
|
|
|
| 43 |
|
|
BEGIN { |
| 44 |
|
|
use FindBin qw($Bin); |
| 45 |
|
|
#require "$Bin/use_libs.pl"; |
| 46 |
joko |
1.2 |
#use org::netfrag::preambel; |
| 47 |
joko |
1.1 |
} |
| 48 |
|
|
|
| 49 |
|
|
use lib qw( ../../../libs ../libs ../etc ); |
| 50 |
|
|
|
| 51 |
|
|
use Data::Dumper; |
| 52 |
|
|
use File::Find; |
| 53 |
|
|
use Getopt::Easy; |
| 54 |
|
|
|
| 55 |
joko |
1.2 |
|
| 56 |
joko |
1.1 |
# ---------------------------------------- |
| 57 |
|
|
package main; |
| 58 |
|
|
|
| 59 |
|
|
my $settings; |
| 60 |
|
|
|
| 61 |
|
|
sub wanted { |
| 62 |
|
|
my $pattern = $settings->{options}->{regex}; |
| 63 |
joko |
1.3 |
my $pattern_exclude = $settings->{options}->{'regex-exclude'}; |
| 64 |
joko |
1.1 |
#print "pattern: $pattern", "\n"; |
| 65 |
|
|
if ($File::Find::name =~ m/$pattern/) { |
| 66 |
joko |
1.3 |
if ($pattern_exclude && $File::Find::name =~ m/$pattern_exclude/) { |
| 67 |
|
|
return; |
| 68 |
|
|
} |
| 69 |
joko |
1.1 |
print $File::Find::name, "\n"; |
| 70 |
|
|
#replaceInFile($File::Find::name); |
| 71 |
|
|
#exit; |
| 72 |
|
|
} |
| 73 |
|
|
} |
| 74 |
|
|
|
| 75 |
|
|
sub main { |
| 76 |
|
|
|
| 77 |
|
|
my $defaults = { |
| 78 |
|
|
options => { |
| 79 |
|
|
'recursive' => 0, |
| 80 |
|
|
'regex' => '.*', |
| 81 |
|
|
}, |
| 82 |
|
|
args => [qw( . )], |
| 83 |
|
|
}; |
| 84 |
|
|
|
| 85 |
|
|
my $optReader = Getopt::Easy->new(); |
| 86 |
|
|
$optReader->merge_defaults($defaults); |
| 87 |
|
|
$optReader->merge_cli_arguments(); |
| 88 |
|
|
$settings = $optReader->getOptions(); |
| 89 |
|
|
|
| 90 |
|
|
#print Dumper($settings); exit; |
| 91 |
|
|
|
| 92 |
|
|
#find(\&wanted, $settings->{args}->[0]); |
| 93 |
|
|
my $where = $settings->{args}->[0]; |
| 94 |
|
|
find(\&wanted, $where); |
| 95 |
|
|
|
| 96 |
|
|
} |
| 97 |
|
|
|
| 98 |
|
|
main(); |
| 99 |
|
|
|
| 100 |
|
|
1; |
| 101 |
|
|
__END__ |