Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2016-09-25 06:36 GMT
Find Nodes?
    Voting Booth?
    Extraterrestrials haven't visited the Earth yet because:

    Results (464 votes). Check out past polls.