Capital letters - aargh

Started by stevenrw, Jul 26, 2007, 12:12:14

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

stevenrw

I have loads of files that have been named in capitals. It's driving me mad having the things shouting at me.
Does anybody know of free software that can change the case of filenames in windows explorer easily?

Rik

A quick Google found that it was easy to do in Linux, and that sites offering software to do it in Windows were regarded as suspect (spyware etc) by McAfee. However, I did find this solution:

"mkdir /tmp/hold && ls | while read inf; do test -f $inf && { low=$(echo
$inf | tr '[:upper:]' '[:lower:]'); cp $inf /tmp/hold/$low; }; done

The above is one(1) line  and will copy the file to the
directory /tmp/hold and give them the lower case versions on there
names. After you've checked that all files have been properly copied and
renamed you can then DELETE the originals and move the new version back
to the former place."
Rik
--------------------

This post reflects my own views, opinions and experience, not those of IDNet.

stevenrw

Thanks for that Rik, but can you now explain how I convert this into a macro then run the macro for a group of files please?
I've never tried running macro commands in windows.

Rik

It's a DOS-level command, but running it produces a syntax error. :(
Rik
--------------------

This post reflects my own views, opinions and experience, not those of IDNet.

Rik

Just found this piece of software, haven't tried it...

http://www.altap.cz/salam_en/freeware.html
Rik
--------------------

This post reflects my own views, opinions and experience, not those of IDNet.

Rik

Later still...

Cut'n'paste this, and save it as a BATch file, run it in the folder where you want to change the filenames.

@Echo Off
    If :'==%1' If Not %2'==' Goto %2
    Set | Find "winbootdir=" > NUL
    If ErrorLevel 1 If Not %OS%'==Windows_NT' For %%C In (Echo Goto:End) Do %%C Windows 9x/NT/2K Batch File.
    If Not %1'==/?' Goto Begin
    Echo Renames all file names in current dir to lower case file names.
    Echo.
    Echo Lowname
    Goto End
   :Begin
    Echo Rename all file names in current dir to lower case file names?
    Echo.
    Echo Press [Ctrl-C] to cancel or:
    Pause
    If Not %OS%'==Windows_NT' Goto Win9x
    For /F "tokens=*" %%F In ('Dir /B /L') Do Move "%%F" "%%F"
    Goto End
   :Win9x
    LfnFor On
    For %%F In (*.*) Do Call %0 : Mc2lc "%%F"
    LfnFor Off
    If Exist %TEMP%.\Tmp.bat Del %TEMP%.\Tmp.bat
    For %%V In (Mix Low) Do Set %%Vcase=
    Goto End
   :Mc2lc (Mixcase-to-Lowcase)
    For %%F In (%3) Do Set Mixcase=%%F
    Ren "%Mixcase%" "Set Lowcase=%Mixcase%"
    Dir /B /L "Set Lowcase=%Mixcase%" > %TEMP%.\Tmp.bat
    Call %TEMP%.\Tmp.bat
    Ren "Set Lowcase=%Mixcase%" "%Lowcase%"
   :End
Rik
--------------------

This post reflects my own views, opinions and experience, not those of IDNet.

john

You could also do this using Perl but you'd have to download the Perl language first. It's not difficult and you may find it useful for other tasks as it provides some Unix/Linux functionality in Windows.

I'd try Rik's code first but if you want to use Perl then create a file called 'chgcase.pl' and enter the following :

###################################################################
#!perl

  use File::Find;
  use File::Basename;
  use Cwd;
  use File::Copy;

  my $dir = getcwd;

  print "Processing files in directory $dir\n";
  find(\&wanted, $dir);

sub wanted {

    if(-f $File::Find::name)
    {
   ($name,$suffix) = split /\./, $_;
   $path = $File::Find::dir;

     if($name =~ /^[A-Z]+$/){&rename($File::Find::name)}
    }
}

sub rename {

  print "\n'$path',\t'$name',\t'$suffix'\n";

  $source = shift;
  $new = lc($name);
# $new = ucfirst($new); # Delete the '#' at the beginning of this line to leave the first character in upper case (Title case).

  ($dest = $source) =~ s/\/$name\./\/$new\./;

  print "\nrename $source\n";
  print "    to $dest\n";

# print "\n y/n > ";$ans = <STDIN>;chomp($ans);if($ans !~ /^y$/i){return} # remove the '#' from the beginning of this line to prompt for renaming of the file.

  move($source,$dest) or warn "Rename failed: $!";
}
####################################################################

Execute the above file from the directory where the files you want to re-name are. It will also look in subdirectories too.

If you have any queries regarding it then please feel free to PM me.

(The above was written fairly quickly and although it works there's probably some scope for cleaning it up a bit)