Sridhar Dhanapalan wrote:

>I've got two possible solutions. The first is a Perl script I found somewhere
>(attached) which is designed to change the case of filenames. The second is the
>'rename' command, which is part of the util-linux Mandrake package (type 'man
>rename' for details)
>
OK I think I unserstand.
Let me run my understanding past you.
If I copy the perl script below into a text file and place in somewhere
like /usr/bin/ or /usr/local/bin,
and then run some command to initiate it ,
 
Then CD to directory sources in a shell,
and type something ( ? )
this script could be run and hey presto,
all done.    Yes ?

because if so this would be very handy.


>  
>
>------------------------------------------------------------------------
>
>eval 'exec perl $0 ${1+"$@"}'
>if 0;
># don't modify below here
>#-------------------------
>$ver = '1.2';
># chcase 1.2
># Changes case of filenames
># http://www.blemished.net/chcase.html
># [EMAIL PROTECTED]
>#
># 1.2 - June 22, 2000
>#      Added -n since escape characters don't work on all terminals
>#       Added -l to rename & follow symbolic links
>#       Allowed options to be put together eg: chcase -rdou ...
># 1.1 - Feb 29, 2000
>#       Added ability to supply perl expressions
># 1.0 - Jan 26, 2000
>#       Initial Release
>
>sub ERR {
>print "\nchcase $ver\n";
>if (shift) {
>print<<EOT;
>EXAMPLES:
>  
>
>>chcase My.DOC *.JPG FileName.txt
>>    
>>
>  => these specific files are changed to lower case
>
>  
>
>>chcase -rd '*'
>>    
>>
>  => all files and sub dirs to lower case, start in current dir, recurse
>
>  
>
>>chcase -s pics '*.jpg' '*.gif'
>>    
>>
>  => rename .jpg and .gif files in pics dir to lower case
>
>  
>
>>chcase -rous /tmp/junk 'a??b*.txt'
>>    
>>
>  => starting from /tmp/junk and recursing, change files matching this
>     mask to all upper case, overwrite if file exists
>
>  
>
>>chcase -x 's/99dec/jan2000/' -x 's/ /_/g' '*.doc'
>>    
>>
>  => renames *.doc files replacing 99dec with jan2000,
>     and replacing all spaces with underscores
>
>  
>
>>chcase -x 'tr/a-zA-Z0-9.//cd' -x 's/jpg/jpg/i' '*'
>>    
>>
>  => removes all non-alphanumeric characters except for '.' and
>     changes the pattern "jpg" to lower case if it isn't already
>
>  
>
>>chcase -r
>>    
>>
>  => displays directory structure
>EOT
>} else {
>print<<EOT;
>USAGE:
>chcase [-erdouqnl] [-s <dir>] [-x '<perl exp>'] '<mask>'
>
>       -e       : Print EXAMPLES - very helpful!
>       -r       : Rename recursively
>       -d       : Also rename subdirectories
>       -o       : Overwrite if file exists
>       -u       : Change to upper case (default is lower)
>       -q       : Quiet mode (no output)
>       -n       : No escape characters (for bold output)
>       -l       : Rename & follow symbolic links (default is not to)
>       -s <dir> : Specify starting directory
>
>-x '<perl exp>' : Perl expression to operate on filename
>                  usually s/// or tr///  (yes you need the quotes)
>                  case of filename not changed when this option used
>                  you can supply multiple expressions
>
>       '<mask>' : Mask to rename  (quotes are nice to have here)
>                  not case sensitive, you can use multiple masks
>             -or- just supply the filename(s) on the command line
>
>EOT
>}
>exit;
>}
>
>sub chcase {
> $_ = $old = shift;
> foreach $m (@mask) {
>   if (/^$m$/i) {
>     if (@exp) { foreach $x (@exp) { eval $x; } }
>     else { $_ = $upper ? uc : lc; }
>     return($_) if (-d);
>     return($_) if (!$overw && -f || ($old eq $_));
>     $error = (rename($old, $_)) ? '' : "$bold -> cannot rename$unbold";
>     if (-d) { print @h, "$bold$old/  =>  $_$unbold\n" unless $quiet; }
>     else { print @h, "$old  =>  $_$error\n" unless $quiet; }
>   }
> }
> return($_);
>}
>
>sub procdir {
> $_ = shift;
> chdir($_) || die "Couldn't chdir into $_\n$!";
> print @h, "$bold$_$unbold\n" unless $quiet;
> push @h, '|__ ';
> opendir(D,'.');
> foreach (readdir(D)) {
>   next if (($_ eq '.') || ($_ eq '..'));
>   next if (-l && !$links);
>   if (-d) {
>     if ($rendir) { $_ = &chcase($_); next if $error; }
>     if ($recur) { &procdir($_); chdir('..'); pop @h; }
>   } else { &chcase($_); }
> }
> closedir(D);
>}
>
>
>$bold   = "\033[01m";
>$unbold = "\033[0m";
>$dir = '.';
>
>&ERR unless @ARGV;
>while (@ARGV) {
> $_ = shift;
> if (/^-/) {
>   &ERR unless /^-[erdouqnlsx]+$/;
>   /e/ && &ERR(1);
>   /r/ && $recur++;
>   /d/ && $rendir++;
>   /o/ && $overw++;
>   /u/ && $upper++;
>   /q/ && $quiet++;
>   /n/ && ($bold=$unbold='');
>   /l/ && $links++;
>   /s/ && ($dir = shift) && ($dir =~ s/\/$//);
>   /x/ && (push @exp, shift);
> } else {
>   if (/(.*)\/([^\/]*)$/) { $dir = $1; $_ = $2; }
>   s/\\/\\\\/g;
>   s/\./\\./g; s/\+/\\+/g; s/\[/\\[/g;
>   s/\]/\\]/g; s/\|/\\|/g; s/\^/\\^/g;
>   s/\*/\.\*/g; s/\?/\./g;
>   push @mask, $_;
> }
>}
>
>&procdir($dir);
>  
>
>
>  
>
John

-- 
John Richard Smith
[EMAIL PROTECTED] 




Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com

Reply via email to