linux目录格的正则表达式,Linux的 - 要检查可能重复目录(也许正则表达式需要)...

跟进:

我做了我需要通过编码下面的Perl脚本使用。这是我第一次使用Perl脚本(并且我必须学习Perl来编写它 - 所以不要对我很难:)

#!/usr/bin/perl

# README

#

# Checks a folder for Albums that are similar

# eg :

# Arist-Back_In_Black-(Remastered)-2001-XXX

# Artist-Back_In_Black-(Reissue)-2000-YYY

#

# Script prompts you for which one to "zz" (putting zz in front of the file name you can delete it later)

#

# CONFIG

#

# Put your mp3 directory path in the $mp3dirpath variable

#

$mp3dirpath = '/data/downloads/MP3';

# END CONFIG

@txt= qx{ls $mp3dirpath};

sort (@txt);

$re1='.*?';

$re2='(?:[a-z][a-z0-9_]*)';

$re3='.*?';

$re4='((?:[a-z][a-z0-9_]*))';

$re=$re1.$re2.$re3.$re4;

$foreach_count_before=0; #Setups up counter

$foreach_count_after=1; #Setups up counter

$number_in_arry = scalar (@txt);

while ($foreach_count_before < $number_in_arry) {

if ($txt[$foreach_count_before] =~ m/$re/is)

{

$var1=$1;

}

if ($txt[$foreach_count_after] =~ m/$re/is)

{

$var2=$1;

}

if ($var1 eq $var2)

{

print "-------------------------------------\n";

print "$txt[$foreach_count_before] \n";

print "MATCHES \n";

print "\n$txt[$foreach_count_after] \n";

print "Which Should I Remove? \n";

print "[1] $txt[$foreach_count_before]\n";

print "[2] $txt[$foreach_count_after]\n";

print "[Any Other Key] Take No Action\n\n";

$answer = <>; # Get user input, assign it to the variable

if ($answer == "1") {

print "ZZing $txt[$foreach_count_before]";

$originalfilename = $mp3dirpath . '/' . $txt[$foreach_count_before];

$newfilename = $mp3dirpath . '/' . 'zz' . $txt[$foreach_count_before];

$originalfilename = trim($originalfilename);

$newfilename = trim($newfilename);

qx(mv $originalfilename $newfilename);

}

elsif ($answer == "2") {

print "ZZing $txt[$foreach_count_after]";

$originalfilename = $mp3dirpath . '/' . $txt[$foreach_count_after];

$newfilename = $mp3dirpath . '/' . 'zz' . $txt[$foreach_count_after];

$originalfilename = trim($originalfilename);

$newfilename = trim($newfilename);

print "mv $originalfilename $newfilename";

qx(mv $originalfilename $newfilename);

}

else {

print "Taking No Action";

}

}

$foreach_count_before++;

$foreach_count_after++;

}

# SubRoutine For Trimming White Space from variables

sub trim($)

{

my $string = shift;

$string =~ s/^\s+//;

$string =~ s/\s+$//;

return $string;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值