Beefy Boxes and Bandwidth Generously Provided by pair Networks kudra
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Recursive Rename

by coolmichael (Deacon)
on Apr 09, 2001 at 11:54 UTC ( #70944=CUFP: print w/ replies, xml ) Need Help??

This is a handy little script to traverse a file directory and prompt the user to rename files that match a specific pattern ($re). When prompted, type the new name of the file. The script will give you a confirmation prompt before overwriting or moving any files.

Please give me any comments you wish, preferably some that are related.

#!/usr/bin/perl -w use strict; use File::Find; my $new; my $ans; my $re='~'; my $start='/home/michael'; finddepth(\&wanted, $start); sub wanted { return unless m/$re/; print "$File::Find::name\n-->"; chomp ($new = <>); return if (length $new == 0); if(($new =~ m|^\.\./|) || ($new =~ m|/|)){ $ans="?"; while($ans !~ m/^[y|n]$/i){ print "move? (y|n): "; chomp ($ans =<>); } return if ($ans =~ /n/); } if(-e $new){ $ans="?"; while($ans !~ m/^[y|n]$/i){ print "overwrite? (y|n): "; chomp ($ans =<>); } return if ($ans =~ /n/); } rename ($_, $new); }

michael
the blue haired monk

Comment on Recursive Rename
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://70944]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (14)
As of 2014-04-24 11:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (565 votes), past polls