문제

When I have a folder with about 5000 images and I use the following code:

my $path= "./foo/images"
my @files = File::Find::Rule->file()->name('*.jpg')->in($path);

I should get 5000 Images in my Array.

But are there equivalents with perl or a shell function like tail and head, or any other way, to get the last 100 images for example?

도움이 되었습니까?

해결책 2

Just realised... File::Find::Rule completly mixes up the images... so we need a sort additionally before slicing the Array

so finally I/we have to use the following:

for the first 5:

my @files = (sort File::Find::Rule->file()->name('*.jpg')->in($path))[0 .. 4];

for the last 5:

my @files = (reverse sort File::Find::Rule->file()->name('*.jpg')->in($path))[0 .. 4];

다른 팁

You can use an array slice. This gets the 1st 5 returned:

my @files = (File::Find::Rule->file()->name('*.jpg')->in($path))[0 .. 4];

This gets the last 5:

my @files = (reverse File::Find::Rule->file()->name('*.txt')->in($path))[0 .. 4];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top