debugging spacemall
[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
24 # call the primary subroutine to rename the files specified.
25
26 &rename_lower(@ARGV);
27
28 exit 0;
29
30 # takes a list of directories as arguments.  all of the files in each
31 # directory are renamed to their lower case equivalent.
32
33 sub rename_lower {
34   # go through the list of files passed in.
35   foreach $current (&glob_list(@_)) {
36 #print "unfiltered: '$current'\n";
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 "\n";
48
49 #print "command A is: rename [$old_name] [$intermediate_name]\n";
50 #print "command B is: rename [$intermediate_name] [$new_name]\n";
51 #print "\n";
52       rename($old_name, $intermediate_name)
53           || die "failed to do initial rename";
54       rename($intermediate_name, $new_name)
55           || die "failed to do secondary rename";
56       print "'$old_name' => '$new_name'\n";
57     }
58   }
59 }
60