#! /usr/bin/env perl # (C) Copyright 2000, B¿rge Lindberg, CPK, Aalborg University, Denmark # Comments: lindberg@cpk.auc.dk # # # uctree.pl: # # Walks a tree starting at argument 1 and renames all files and # directories here under to their upper case equivalent # # Tested under Unix (SunOS 5.6) # --------------------------------------------------- use locale; use File::Basename; $DirSeparator = "/"; $MoveCommand = "mv"; unless ($#ARGV == 0) { print STDERR "usage: $0 \n"; exit; } $vol = $ARGV[0]; $totalsize = 0; printf "The following files/directories have been renamed to uppercase:\n"; printf "-" x 79; printf "\n"; processdir($vol); printf "-" x 79; printf "\n"; printf "Total size of files under $vol is: $totalsize bytes\n"; exit; # --------------------------------------------------- # sub routine getdir # --------------------------------------------------- sub getdir { # return file names in directory, not including hidden files my($dir) = @_; opendir(DIR,$dir) || die "Could not open directory $dir : $!\n"; my(@fns) = readdir(DIR); closedir(DIR); return grep(!/^\./,@fns); # remove filenames starting with a . } # --------------------------------------------------- # sub routine processdir # --------------------------------------------------- sub processdir { my($dir) = @_; opendir(DIR,$dir) || die "Could not open directory $dir: $!\n"; foreach $file (sort (&getdir($dir))) { my($FullFileName) = $dir . $DirSeparator . $file; if (-f $FullFileName) { # ordinary file $size = (stat($FullFileName))[7]; $totalsize += $size; printf "$FullFileName\r"; movefile ($FullFileName); } elsif (-d $FullFileName) { # directory processdir($FullFileName); printf "$FullFileName\r"; movefile ($FullFileName); } } } # --------------------------------------------------- # sub routine movefile # --------------------------------------------------- sub movefile { my($FullName) = @_; $BaseName = basename($FullName); $DirName = dirname($FullName); $UCBaseName = uc($BaseName); if ($UCBaseName ne $BaseName) { system ("$MoveCommand $DirName$DirSeparator$BaseName $DirName$DirSeparator$UCBaseName"); printf "\r$DirName$DirSeparator$UCBaseName\n"; } else { $WhiteSpace = ""; $_ = $FullName; $TmpFullName = $_; chop; while ($TmpFullName ne $_) { $TmpFullName = $_; chop; $WhiteSpace .= " "; # add single white space char } printf "$WhiteSpace\r"; # erase line printed on screen } }