By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,374 Members | 2,014 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,374 IT Pros & Developers. It's quick & easy.

Changing the extensions of multiple files using Perl Regex?

P: 3
Does anyone know a regular expression that will rename multiple files that have different extensions to have the same extension. For example, you could use this code when several text files exist in a directory but have slightly different extensions such as .txt,. TXT, or text. This expression should show how to rename them to all have .txt extensions.


I understand i will nedd [] the character class so it contains a hypen, dot, slash and w+ d+ to show the filename to be of any charcter and digit
What else do i need to include in the expression?

Regards, David.
Aug 4 '08 #1
Share this Question
Share on Google+
3 Replies


eWish
Expert 100+
P: 971
If you want the match to be case-insensitive the you can use the i flag.

There are several perl docs that cover regular expression.
perlretut
perlrequick
perlfaq6
perlop

Also check out the perl section in the "Howtos" for some additional tutorials.

--Kevin
Aug 4 '08 #2

KevinADC
Expert 2.5K+
P: 4,059
Does anyone know a regular expression that will rename multiple files that have different extensions to have the same extension. For example, you could use this code when several text files exist in a directory but have slightly different extensions such as .txt,. TXT, or text. This expression should show how to rename them to all have .txt extensions.


I understand i will nedd [] the character class so it contains a hypen, dot, slash and w+ d+ to show the filename to be of any charcter and digit
What else do i need to include in the expression?

Regards, David.

No doubt in my mind this is school or class work.

Regular expressions can not rename files, only find the files you are looking for. To rename a file you have to use the rename() function.
Aug 4 '08 #3

eWish
Expert 100+
P: 971
As Kevin has pointed out you will need the rename() function. In addition to that I would suggest using File::Find or File::Find::Wanted modules to located the files that you are after. I prefer the latter of the two.

--Kevin
Aug 4 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.