Click here to Skip to main content
13,050,319 members (121,162 online)
Rate this:
Please Sign up or sign in to vote.
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:


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
and it would populate the local variables "group", "ep", and "crc" to use in the batch rename.

How might I approach this?
Posted 15-Dec-12 13:44pm
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).
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Use the Regular expression groups:
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:

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.)
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Check out[^].
The source code is on CodePlex.
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 17 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100