root/juggler/branches/2.0_alpha_4/scripts/stripvj_filename.pl

Revision 6169, 0.9 kB (checked in by kevn, 7 years ago)

strip vj from the front of a filename…

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1 #!/usr/bin/perl
2 use File::Basename;
3 use Getopt::Std;
4
5 # Do this to include the path to the script in @INC.
6 my $path;
7
8 BEGIN {
9    $path = (fileparse("$0"))[1];
10 }
11
12 use lib($path);
13 use RecurseDir;
14
15 # get opts:
16 getopts('d:e:ha');
17
18 my $working_dir = "$opt_d" || ".";
19 my @extensions = split( /:/, "$opt_e" );
20
21 $RecurseDir::print_cur_dir = 1;
22 $RecurseDir::pass_rec_func_cur_file = 1;
23
24
25
26 recurseDir( $working_dir );
27
28 exit 0;
29
30 sub recurseFunc
31 {
32    my $filename = shift;
33
34    return unless checkName("$filename");
35
36    if ( $filename =~ m/vj(.*?\..*)$/is)
37    {
38       print "mv $filename $1\n";
39       system("mv $filename $1");
40    }
41 }
42
43 sub checkExt( $ )
44 {
45    my $filename = shift;
46
47    foreach (@extensions)
48    {
49       if ( $filename =~ /\.$_$/ )
50       {
51          return 1 ;
52       }
53      
54    }
55    return 0;
56 }
57
58 sub checkName( $ )
59 {
60    my $filename = shift;
61
62    if (!checkExt( $filename ))
63    {
64       return 0
65    }
66
67    return 1 if $filename =~ /vj.+?\..*/;
68    return 0;
69 }
Note: See TracBrowser for help on using the browser.