473,378 Members | 1,436 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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
3 2859
eWish
971 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
4,059 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
971 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

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

Similar topics

3
by: Martin Lucas-Smith | last post by:
Is there some way of using ereg to detect when certain filename extensions are supplied and to return false if so, WITHOUT using the ! operator before ereg () ? I have an API that allows as an...
17
by: Michael McGarry | last post by:
Hi, I am just starting to use Python. Does Python have all the regular expression features of Perl? Is Python missing any features available in Perl? Thanks, Michael
0
by: Tim Engler | last post by:
Hi, I'm writing an install script and want to be able to install files and directories where some files are owned by one user and other files are owned by another, but I don't have access to...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
19
by: laredotornado | last post by:
Hello, Using PHP 4, what are the shortest amount of lines I can write to delete all the files in a given directory? Thanks for your help, - Dave
0
by: Xah Lee | last post by:
Interactive Find and Replace String Patterns on Multiple Files Xah Lee, 2006-06 Suppose you need to do find and replace of a string pattern, for all files in a directory. However, you do not...
19
by: =?Utf-8?B?QnJpYW4gQ29vaw==?= | last post by:
This is an example of the data; 2007/07/27 11:00:03 ARES_INDICATION 010.050.016.002 404.2.01 (6511) RX 74 bytes 2007/07/27 11:00:03 65 11 26 02 BC 6C AA 20 76 93 51 53 50 76 13 48...
2
by: drjay | last post by:
I'm trying to get my script to parse a bunch of files and grab data between the <title></> and <blah></> tags. Yes yes, I'm parsing html with regex, it works though. :) The issue I have is...
5
by: mohi | last post by:
hello everyone i m positing this again but can't help as im not finding any solution to this . my problem is i have to browse a directory to search for all the files in it and process certain...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.