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).

On Mon, 23 Sep 2002 08:52:44 +0100, "Tony S. Sykes" <[EMAIL PROTECTED]>
wrote:
> It works fine on my 8.2, try using `ls` instead of * (Use the single
> quote from the key next to the one).
> 
> -----Original Message-----
> From: John Richard Smith [mailto:[EMAIL PROTECTED]]
> Sent: Monday, September 23, 2002 8:16 AM
> To: Anuerin G. Diaz; NEWBIE 1
> Subject: Re: [newbie] File conversion
> 
> 
> Anuerin G. Diaz wrote:
> 
> >hi john,
> >
> >  sorry for replying direct but i cant post to the list. ;-)
> >
> >  here is one post from the local LUG here in the Philippines which
> >seems to be what you want...
> >
> >[quote]
> >Because FAT is not case sensitive and most, if not all, UNIX
> filesystems
> >are. A short script I got from a list of tips as a newbie might help:
> >
> >    $ for i in *; do mv "$i" "`echo "$i" | tr A-Z a-z`"; done;
> >
> >This renames every file in the current directory to all lowercase
> >filenames. I've added double-quotes around the back-ticked "converter"
> >to allow it to handle filenames with embedded spaces as well.
> >[/quote]
> >
> >ciao!
> >
> >John Richard Smith wrote:
> >  
> >
> >>For reasons I need not go into, I transfer *.JPG files across from
> >>Windblows to Mandrake and work on them in gimp,and
> >>when I'm finished I have a montage of prints I wish to assemble
> >>as a composite.
> >>
> >>I've hit a snag.
> >>
> >>Winblows names it's files in higher case.
> >>Montage(the programme, part of image magic) seems only willing
> >>to work with lowercase named files. There are too many to manually
> >>retype.
> >>
> >>How can I convert windblows named *.JPG files to *.jpg named
> >>files on the command line ?
> >>
> >>John
> >>
> >>    
> >>
> >  
> >
> Here is some of my first efforts,
> ]# cd /mnt/ext2-vol6/downloads2/digitalcam/set002
> 
> set002]# $ for i in *; do mv "$i" "`echo "$i" | tr A-Z a-z`"; done;
> bash: syntax error near unexpected token `do'
> 
> set002]# $ for i in *; do mv "$i" "`echo "$i" | tr A-Z a-z`";
> bash: syntax error near unexpected token `do'
> 
> set002]# $ for i in *; mv "$i" "`echo "$i" | tr A-Z a-z`"; done;bash:
> syntax error near unexpected token `;'
> 
> set002]# $ for i in * do mv "$i" "`echo "$i" | tr A-Z a-z`"; done;
> bash: syntax error near unexpected token `;'
> 
> 
> As a bash script newbie I'm obviously doing something
> quite wrong here. Any idea what it is, as I think this
> will work when I learn how to prpoperly execute it.
> Incidentally, I note there is a pipe so it's a two
> part operation inwhich the standard output of the first part is fed
> directly into the standard input of the second
> element.
> John

-- 
Sridhar Dhanapalan

     "We like to think of ourselves as the Microsoft of the energy world"
                    -- Kenneth Lay, former CEO of Enron
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);
Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com

Reply via email to