first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / scripts / files / renlower.pl
1 #!/usr/bin/perl
2
3 ###############################################################################
4 #                                                                             #
5 #  Name   : renlower                                                          #
6 #  Author : Chris Koeritz                                                     #
7 #  Rights : Copyright (C) 1996-$now by Author                                 #
8 #                                                                             #
9 #  Purpose:                                                                   #
10 #                                                                             #
11 #    This program renames all of the files in a specified directory to have   #
12 #  completely lower case names.                                               #
13 #                                                                             #
14 ###############################################################################
15 #  This program is free software; you can redistribute it and/or modify it    #
16 #  under the terms of the GNU General Public License as published by the Free #
17 #  Software Foundation; either version 2 of the License or (at your option)   #
18 #  any later version.  See: "http://www.gruntose.com/Info/GNU/GPL.html" for a #
19 #  version of the License.  Please send any updates to "fred@gruntose.com".   #
20 ###############################################################################
21
22 require "filename_helper.pl";
23 require "importenv.pl";
24
25 # call the primary subroutine to rename the files specified.
26
27 &rename_lower(@ARGV);
28
29 exit 0;
30
31 # takes a list of directories as arguments.  all of the files in each
32 # directory are renamed to their lower case equivalent.
33
34 sub rename_lower {
35   # go through the list of files passed in.
36   foreach $current (&glob_list(@_)) {
37     if ($current =~ /[A-Z]/) {
38 #print "current is '$current'\n";
39       local $old_name = $current;
40 #print "old name is '$old_name'\n";
41       local $dir = &dirname($current);
42       local $file = &basename($current);
43       (local $lc_name = $file) =~ tr/[A-Z]/[a-z]/;
44       local $new_name = $dir . $lc_name; 
45 #print "new name='$new_name'\n";
46       local $intermediate_name = $dir . "RL" .  rand() . ".tmp";
47 #print "command A is: rename [$old_name] [$intermediate_name]\n";
48 #print "command B is: rename [$intermediate_name] [$new_name]\n";
49       rename($old_name, $intermediate_name)
50           || die "failed to do initial rename";
51       rename($intermediate_name, $new_name)
52           || die "failed to do secondary rename";
53     }
54   }
55 }
56