Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Recursively renaming files matching specific patterns (was CityCat)

by CityCat
on Sep 17, 2002 at 20:53 UTC ( #198636=perlquestion: print w/replies, xml ) Need Help??
CityCat has asked for the wisdom of the Perl Monks concerning the following question:

And another one task. I know - it is quite simple. But maybe somebody have code for this :

There is a directory tree with hundreds of files also there several levels of subdirs, you need to change all occurrences of "xxx" to "yyy" in all files which end! s with "htm".

Edited: ~Tue Sep 17 21:23:30 2002 (GMT) by footpad: Retitled and added HTML formatting, per Consideration.

  • Comment on Recursively renaming files matching specific patterns (was CityCat)

Replies are listed 'Best First'.
Re: Recursively renaming files...
by footpad (Monsignor) on Sep 17, 2002 at 22:18 UTC

    Welcome to the Monastery!

    You are correct, this is a pretty commonly asked question. Have you checked some of the available materials? Here are a few possible avenues for you to explore, which I found by spending a few minutes working with some of the basic tools we have available:

    1. Typing rename file into the Search box shown above located these nodes:

    2. Typing Recursive rename into the above Search box lead to a node with the same title, which uses the File::Find (alt.) module mentioned by insensate.

      You may notice that it's in a section called Cool Uses for Perl. We have a few different sections along these lines, each showcasing a variety of Perl techniques that can be adapted for a variety of purposes.

    3. Also, the Files section of Categorized Questions and Answers lists a potentially useful entry: How do I do a bulk rename?

    4. Are you aware of the POD documentation provided with Perl? I noticed that perlfaq5 (which you can read from the command line by typing perldoc perlfaq5) contains an item called How can I reliably rename a file?.

    5. Also, one of our most prolific monks maintains an archive of the magazine articles he's written regarding Perl. Quickly browsing those, I found several that you may find interesting, including:

      Note that these are roughly in order of publication, so you may find the ones at the bottom of the list more helpful than the ones at the top of the list. Remember: Perl is dynamic and "best practices" evolve over time.

    6. Update:1 In another area of the site, Best Nodes, you'll find threads that've gotten the hightest response from the members. You might be interested in this one, which is one of the oldest threads on the site. While a node's appearance on Best Nodes isn't always a sign of node quality, it does indicate a form of appreciation.

      If you choose to continue to participate, you may find these nodes useful as well. /update

    As I said, this is a short list. There are many relevant nodes and lots of existing material on the subject. Part of the fun is locating them.

    Be sure to also check out some of these nodes; they're designed to help you use the Monastery's resources most efficiently.


    1 - How could I forget paco?

Re: Recursively renaming files matching specific patterns
by insensate (Hermit) on Sep 17, 2002 at 21:13 UTC

    This definitely seems like homework...look at the File::Find module as a place to start.


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (10)
As of 2017-01-24 13:08 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (204 votes). Check out past polls.