S
soren625
I am rather new to Perl and I'm looking for a little direction.
How can I use File::Find to step recursively through a directory tree
and then only manipulate *one* file per directory it encounters. What I
am trying to do specifically is copy the first image file in each
directory up to the next highest directory ("../"). Then I'd like to
rename it with the directory name it came from (in other words, copy it
from "/images/image1.jpg" to "/images.jpg")
I am able to copy *all* images to the next highest directory using the
following code:
#!/usr/bin/perl
use File::Find;
use File::Copy;
use Cwd;
find(\&wanted, cwd);
sub wanted {
if(/(jpg|jpeg|jpe|png|bmp|gif)$/i) {
copy $_, "../$_"
}
}
How can I get it to copy only the first image it encounters in any
directory *and* rename it with the directory name it came from?
Thanks
How can I use File::Find to step recursively through a directory tree
and then only manipulate *one* file per directory it encounters. What I
am trying to do specifically is copy the first image file in each
directory up to the next highest directory ("../"). Then I'd like to
rename it with the directory name it came from (in other words, copy it
from "/images/image1.jpg" to "/images.jpg")
I am able to copy *all* images to the next highest directory using the
following code:
#!/usr/bin/perl
use File::Find;
use File::Copy;
use Cwd;
find(\&wanted, cwd);
sub wanted {
if(/(jpg|jpeg|jpe|png|bmp|gif)$/i) {
copy $_, "../$_"
}
}
How can I get it to copy only the first image it encounters in any
directory *and* rename it with the directory name it came from?
Thanks