Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

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); }

the blue haired monk

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://70944]
Approved by root
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2018-02-25 20:09 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (314 votes). Check out past polls.