Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Convert Extensions Of Files To Lowercase Using Perl

DZone's Guide to

Convert Extensions Of Files To Lowercase Using Perl

·
Free Resource
1. Searches for files having uppercase extensions (can be mixed with numbers and can be multipart eg: TAR.BZ2 ). 
   It does not detect files whose extensions contain both upper and lower cases.  This is intentional, as if you have part of extension lowercase, you probably intentionally left the other part upper case. Changing this behaviour is trivial. Replace that complex (?:[A-Z]*[0-9]*\.*) with a . (a dot). 

2. It then converts them to lowercase.


#!/usr/bin/perl
$files=`ls`;
@files=split(/\n/,$files);
foreach (@files) {
    if(/(.*)\.((?:[A-Z]*[0-9]*\.*)+)$/) {
        $name=$1."."."\L$2\E";
        system("mv $_ $name")
    }
}

Looks quite ugly, but this is what I could do with the Perl I know, and more importantly, it works (at least in my case)!
Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}