我的本地硬盘中有一堆文件夹。以下是文件夹名称:
3 ABC
abc movie (2002) HDTVRip 576p Hindi Eng BHATTI87
Bcd [2011].720p.BRRip.x264.[Dual Audio] [Hindi+English].by K@rtik [ExD Exclusive]
def (2007)
Gaf-DVDRip-AVI
Gadks Of Wc (2012) - DVDRip - 1CD - XviD - Subs - [xDM]
Kah - DVDScr - XviD - 1CDRip - [DDR]
kaslf.kasl .Ljasj [2007] - x264 - AAC - 1 CD DVDRip - ESubs - MDG
我希望所有名称都有一些相似之处,例如每个字符串之间应该有一个空格,即“Gadks Of Wc(2012) - DVDRip - 1CD - XviD - Subs - [xDM]”应该是
Wad的Gadks(2012)DVDRip 1CD XviD Subs [xDM]。
我的逻辑是:
以下是我的剧本:
#!/usr/bin/perl -w
use strict;
my $dir_name = "E:/movie";
opendir READ, $dir_name
or die"Can not found it $!";
my @name = readdir(READ);
my (@split_name, $update_movie_name, $fix_movie_name);
foreach my $name (@name) {
@split_name = split /[\s+\/.\-]/,$name;
$update_movie_name = movie_fun(@split_name);
}
sub movie_fun {
foreach my $movie (@split_name) {
$fix_movie_name = join("",$movie);
}
return ($fix_movie_name);
}
使用此脚本,我只获取文件夹名称的最后一部分。我不知道我在哪里做错了。请帮我解决这个问题。这样我就可以移动我的下一步,即从名称中删除垃圾部分,即“(2012) - DVDRip - 1CD - XviD - Subs - [xDM]”,(2007)等
如果有任何身体可以给我任何其他方式来解决这个问题,那么也没关系。
由于
由于
答案 0 :(得分:0)
#!/usr/bin/perl -w
use strict;
my $dir_name = "/movie";
opendir READ, $dir_name
or die"Can not found it $!";
my @name = readdir(READ);
FOLDER:
foreach my $name (@name) {
# process only directories (skip if folder name . or ..)
next FOLDER if ( (not -d $dir_name.$name) || ($name =~ m{^\.+$}) );
my @split_name = split /[\s+\/.\-]/, $name;
my $update_name = movie_fun(@split_name);
printf "%s -> %s\n", $name, $update_name;
}
sub movie_fun {
my @split_name = @_;
return join '', @split_name;
}
<强>输出强>
3 ABC ->
3ABC
abc movie (2002) HDTVRip 576p Hindi Eng BHATTI87 ->
abcmovie(2002)HDTVRip576pHindiEngBHATTI87
Bcd [2011].720p.BRRip.x264.[Dual Audio] [Hindi+English].by K@rtik [ExD Exclusive] ->
Bcd[2011]720pBRRipx264[DualAudio][HindiEnglish]byK@rtik[ExDExclusive]
def (2007) ->
def(2007)
Gaf-DVDRip-AVI ->
GafDVDRipAVI
Gadks Of Wc (2012) - DVDRip - 1CD - XviD - Subs - [xDM] ->
GadksOfWc(2012)DVDRip1CDXviDSubs[xDM]
Kah - DVDScr - XviD - 1CDRip - [DDR] ->
KahDVDScrXviD1CDRip[DDR]
kaslf.kasl .Ljasj [2007] - x264 - AAC - 1 CD DVDRip - ESubs - MDG ->
kaslfkaslLjasj[2007]x264AAC1CDDVDRipESubsMDG