0

特定のファイル名を持つファイルを、移動元フォルダーから特定の移動先フォルダーに、別の移動先フォルダーに、アルファベット順に、たとえば 5 分ごとに 1 つずつ移動する必要があります。

これは私がこれまでに思いついたものです...

#!/usr/bin/perl
use strict;
use warnings;
my $english = "sourcepath";
my $destination = "destination path";

#for(;;)
#{
opendir(DIR, $english) or die $!;
while (my $file = readdir(DIR))
    {
    next unless (-f "$english/$file");
    next unless ($file =~ m/english/);
    move ("$english/$file", "$destination");
    }
closedir (DIR);
#sleep 10;
#}  
exit 0;

今の問題は、それらをアルファベット順に1つずつ移動できないことです...ポインタはありますか? ありがとう

4

2 に答える 2

2

ファイルをアルファベット順に処理する場合は、並べ替えます。readdirリストを取得するには、リスト コンテキストで使用できます。

opendir(DIR, $english) or die $!;
my @files = sort readdir DIR;
for my $file (@files) {
    # ....
}
于 2013-06-14T08:01:40.113 に答える
2

それ以外の

while (my $file = readdir(DIR))

次のようにアルファベット順にファイルを取得できます。

for my $file (sort readdir(DIR))

strictと の使用に賛成warningsです。perlstyleコードを適切にフォーマットする方法に関するヒントを読むことを検討してください。

于 2013-06-14T08:01:47.060 に答える