Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am looking to write a utility to batch rename a bunch of files at once using a regular expression. The files that I will be renaming all at once follow a certain naming convention, and I want to alter them to a new naming convention using data that's already in the filenames; but not all my files follow the same convention currently.

So I want to be able to write a general use program that lets me input into a textbox during runtime the pattern of the filename, and what tokens I want to extract from the filename to use for renaming.

For example - Assume I have one file named as such:

[Coalgirls]_Suite_Precure_02_(1280x720_Blu-Ray_FLAC)_[33D74D55].mkv

I want to be able to rename this file to:

Suite Precure - Ep 02 [Coalgirls][33D74D55].mkv

This means I would preferably be able to enter into my program before renaming something akin to
[%group%]_Suite_Precure_%ep%_(...)_[%crc%].mkv
and it would populate the local variables "group", "ep", and "crc" to use in the batch rename.

How might I approach this?
Posted
Comments
Sergey Alexandrovich Kryukov 15-Dec-12 21:43pm    
A couple of comments: 1. Matroska is a great thing. 2. You may not like my view, but I would advise: if you want to make a really good usable renamer, make it command-line based, perhaps console only. I would hardly even consider using anything with GUI for such task (but many would disagree).
—SA

Use the Regular expression groups:
\[(?<publisher>.*?)\]_Suite_Precure_(?<ep>\d+)_\((?<group>.*?)\)_\[(?<crc>.*?)\].mkv</crc></group></ep></publisher>
This produces 4 groups, so your example becomes:
Publisher   CoalGirls
Ep          02
Group       12080x720_Blu-Ray_FLAC
CRC         33D74D55
You can then use these in the Regex.Replace to generate the new name:
${Group}_Suite_Precure_${Ep}_(${Publisher})_[${CRC}].mkv
Produces
1280x720_Blu-Ray_FLAC_Suite_Precure_02_(Coalgirls)_[33D74D55].mkv


However, that is not very user friendly! But it is not easy to do it in a friendly way - you need to specify which "chunks" are which group - which means specifying the start and end sequences, and what to "throw away"

(I had a similar problem when renaming large numbers of files, and ended up writing a GUI interface which helped, but frankly was still a PITA to use.)
 
Share this answer
 
Check out http://www.mobzystems.com/tools/RegName.aspx[^].
The source code is on CodePlex.
 
Share this answer
 
Comments
agent154 17-Dec-12 23:15pm    
That tool does exactly what I'm looking for. Thank you very much.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900