0

我的本地硬盘中有一堆文件夹。以下是文件夹名称:

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]”应该是
Gadks Of Wc (2012) DVDRip 1CD XviD Subs [xDM]。

我的逻辑是:

  1. 读取每个文件夹名称
  2. 将所有文件夹名称存储在列表中
  3. 对每个名称进行拆分和加入等操作

下面是我的脚本:

#!/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)等

如果任何机构可以给我任何其他方式来解决这个问题,那么也可以。

谢谢

谢谢

4

1 回答 1

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
于 2012-09-21T06:58:27.497 回答