"Scott R. Godin" wrote:
>
> Rob Dixon wrote:
>
> > Hi Scott.
> >
> > Scott R. Godin wrote:
> >> John W. Krahn wrote:
> >>
> >> > chomp;
> >> > if ( /(.*)\.BMP/ ) {
> >> > print "processing image $_ ..\n";
> >> > system( 'mv', $_, "$1.bmp" ) == 0 or die "system 'mv $_'
> >> > failed: $?";
> >> > }
> >>
> >> next unless /(.*)\.BMP$/;#anchor it to the end of the string!
> >> print "processing image file: $_\n";
> >>
> >> #rename will clobber existing files, so check first!
> >> warn "File exists!: $1.bmp. skipping...\n" && next
> >> if -f "$1.bmp";
> >>
> >> # use perl rather than spawning external processes!
> >> rename( $_, "$1.bmp" ) or die "unable to rename file $_: $!";
> >
> > There's a big [SNIP] here from the end of John's post:
> >
> > John W. Krahn wrote:
> >> However, you could write the whole thing in perl and avoid the pipes
> >> and system().
> >>
> >> #!/usr/bin/perl
> >> use warnings;
> >> use strict;
> >> use File::Find;
> >> use File::Copy;
> >>
> >> find( sub {
> >> return unless -f and /^(.+)\.BMP$/s;
> >> move( $_, "$1.bmp" ) or warn "Cannot move $_: $!";
> >> }, '.' );
> >>
> >> __END__
>
> Yes,. I saw his post after I posted mine.
>
> However, this still doesn't address the issue of clobbering existing files
> (File::Copy documentation makes no mention of this issue). MY whole issue
> was not using external 'mv' when perl already has 'rename', and the
> possible issue of overwriting files that already exist.
Yes, a valid point. Adding a line will fix that:
find( sub {
return unless -f and /^(.+)\.BMP$/s;
warn "$1.bmp already exists.\n" and return if -e "$1.bmp";
move( $_, "$1.bmp" ) or warn "Cannot move $_: $!";
}, '.' );
:-)
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]