rohanan has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I tried looking for my answer here and many other forums and although some were close, it didn't completely do it for me so I planned to post it.
I have a bunch of files in a folder(say C:\Test) and they need to be renamed in a standardized format-

The files shown below-
ChargeOptimisation_january2011.csv 20110101_Bill_inventory.csv Account_20110101_Summary.csv
needs to be renamed to -
ChargeOptimisation.csv Bill_inventory.csv Account_Summary.csv

I need to use keywords like 'ChargeOptimisation','Bill_inventory' as the other characters may be random. Can someone please help me with using regular expressions / rename command to solve this problem.

Thanks, Rohan.

Replies are listed 'Best First'.
Re: Renaming files based on keywords
by SuicideJunkie (Vicar) on Jun 28, 2011 at 16:22 UTC

    This sounds like a good place to start learning basic regex usage.

    See: perlrequick and keep in mind that you won't have to use any of the fancy stuff for this or even the intermediate stuff.

    You'll be matching and substituting your keywords in no time. Just be sure to keep a copy of the original name before you start changing it, so you can do the rename.

    PS: glob may also be useful if you haven't determined the list of files to work on yet.

      Thanks. I will look into it and let you know if I have further questions. Cheers.