467,926 Members | 1,721 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,926 developers. It's quick & easy.

Changing the extensions of multiple files using Perl Regex?

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
  • viewed: 2619
Share:
3 Replies
eWish
Expert 512MB
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 2GB
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 512MB
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.

Similar topics

3 posts views Thread by Martin Lucas-Smith | last post: by
17 posts views Thread by Michael McGarry | last post: by
reply views Thread by Tim Engler | last post: by
32 posts views Thread by tshad | last post: by
19 posts views Thread by laredotornado | last post: by
19 posts views Thread by =?Utf-8?B?QnJpYW4gQ29vaw==?= | last post: by
5 posts views Thread by mohi | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.