/[cvs]/nfo/perl/scripts/archiver/bin/finder.pl
ViewVC logotype

Contents of /nfo/perl/scripts/archiver/bin/finder.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations)
Sat Feb 1 06:41:21 2003 UTC (21 years, 5 months ago) by joko
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +13 -1 lines
File MIME type: text/plain
+ added mechanism using option 'regex-exclude'

1 #!/usr/bin/perl
2
3 ## ------------------------------------------------------------------------
4 ## $Id: finder.pl,v 1.2 2003/02/01 02:52:32 joko Exp $
5 ## ------------------------------------------------------------------------
6 ## $Log: finder.pl,v $
7 ## Revision 1.2 2003/02/01 02:52:32 joko
8 ## + minor update
9 ##
10 ## Revision 1.1 2003/02/01 01:38:35 joko
11 ## + initial commit - partly refactored from replace_cvs.pl
12 ##
13 ## ------------------------------------------------------------------------
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 - 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 =cut
38
39
40 use strict;
41 use warnings;
42
43 BEGIN {
44 use FindBin qw($Bin);
45 #require "$Bin/use_libs.pl";
46 #use org::netfrag::preambel;
47 }
48
49 use lib qw( ../../../libs ../libs ../etc );
50
51 use Data::Dumper;
52 use File::Find;
53 use Getopt::Easy;
54
55
56 # ----------------------------------------
57 package main;
58
59 my $settings;
60
61 sub wanted {
62 my $pattern = $settings->{options}->{regex};
63 my $pattern_exclude = $settings->{options}->{'regex-exclude'};
64 #print "pattern: $pattern", "\n";
65 if ($File::Find::name =~ m/$pattern/) {
66 if ($pattern_exclude && $File::Find::name =~ m/$pattern_exclude/) {
67 return;
68 }
69 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__

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed