Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^3: Changing filename extensions

by jwkrahn (Abbot)
on Nov 16, 2021 at 04:32 UTC ( [id://11138871]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Changing filename extensions
in thread filenames

This may work (UNTESTED):

#!/usr/bin/perl use strict; use warnings; use File::Find; @ARGV == 3 or die "usage: $0 DIR OLD_EXT NEW_EXT\n"; my $dir = $ARGV[ 0 ]; my $old = $ARGV[ 1 ]; my $new = $ARGV[ 2 ]; my @list; find sub { push @list, $File::Find::name if -f && /\.\Q$old\E\z/; }, $dir; foreach my $old_name ( @list ) { my $new_name = $old_name =~ s/\.\Q$old\E\z/.$new/r; rename $old_name, $new_name or die "Cannot rename '$old_name' beca +use: $!"; }

Replies are listed 'Best First'.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11138871]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-19 19:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found