[Perl] renamer v0.2

作者:reistlin 发布时间:September 25, 2010 分类:原创文章

作者: reistlin
来源: http://www.reistlin.com/blog/53
更新时间: 2011.01
版权声明: 原创文章.转载请保留作者信息和原文完整.谢绝任何方式的摘要

perl.gif

googlecode1.gifgooglecode2.gif
[https://reistlin.googlecode.com/svn/trunk/perl/renamer.pl]

#!/usr/bin/perl -w 
 
# Name: renamer v0.2
# Author: reistlin
# Website: www.reistlin.com
# Hotfix: bigyong
# Website: www.bigyong.com
# Date: 2011.01.10
 
use strict;
use Data::Dumper;
 
# Debug Switch
my $debug = 0;
 
# Defined "uppercase" or "lowercase"
# lowercase = 0 (default)
# uppercase = 1
my $file_case = "0";
 
# Defined File Type
my $file_type = "png";
 
# Defined Directory
my $file_dir = "/home/reistlin";
 
opendir(DIR, $file_dir) or die "[Error] [$file_dir] $!\n";
my @list = readdir(DIR);
closedir(DIR);
 
foreach my $tmp (@list) {
                # exclude "." or ".."
                next if ( $tmp =~ m/^\.+$/ );
                # full path
                my $fullpath = $file_dir . "/" . $tmp;
                # rename mode 
                if ( ! -d $fullpath ) {
                        if ( $fullpath =~ m/\.$file_type$/i ) {
                                if ( ( $tmp ne lc($tmp) ) && ( $file_case == 0 ) ) {
                                        rename $tmp, lc($tmp);
                                        print "[OK] Rename Success [lowercase]: $tmp\n";
                                }
                                if ( ( $tmp ne uc($tmp) ) && ( $file_case == 1 ) ) {
                                        rename $tmp, uc($tmp);
                                        print "[OK] Rename Success [uppercase]: $tmp\n";
                                }
                        }
                }
}

标签: perl

评论已关闭