Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
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 having an uproarious good time at the Monastery: (7)
As of 2015-07-31 10:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (276 votes), past polls