Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: FileName Change

by un-chomp (Scribe)
on Aug 21, 2006 at 16:31 UTC ( [id://568601]=note: print w/replies, xml ) Need Help??


in reply to FileName Change

This may, or may not be, what you want:
#!/usr/bin/perl use strict; use warnings; use File::Basename; use File::Find::Rule; my @files = File::Find::Rule->file() ->in( 'c:/test/'); foreach my $file ( @files ) { my ( $old_name, $path ) = File::Basename::fileparse( $file ); my $new_name = $old_name; $new_name =~ s/^ABC/ABCD/; $new_name =~ s/^XYZ/XYZD/; next if $new_name eq $old_name; rename( $path . $old_name, $path . $new_name ) or die "Renaming $old_name to $new_name: $!"; # or copy, as per your update # require File::Copy; # File::Copy::copy( $path . $old_name, $path . $new_name ) # or die "Renaming $old_name to $new_name: $!"; }

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-04-23 11:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found