Page 1 of 1

Renaming Files

Posted: 23 Mar 2018 16:21
by tlm2408
Hi Guy's,

I have a bunch of mp3 files and the lyrics in the same folder in a seperate .txt file. The file name format for the mp3's are for example:

001 - Artist name - song title.mp3

The text files are:

01 - song title.txt
but some are:
01 - song title (with no extension.

I need to rename the files that have the .txt extension to the same format as the .mp3 file so that I end up with:
001 - Artist name - song title.mp3
001 - Artist name - song title.txt

But the ones that have no extension I want to rename as:
zz 001 - Artist name - song title.txt

There are one hundred songs in each folder numbered from 001 - 100.

Sorry I don't know enough about batch files to work out how to do this. Thank you very much for any help.

Re: Renaming Files

Posted: 23 Mar 2018 17:44
by Aacini
Suppose a file with no extension like:

01 - song title

If you want to rename it to:

zz 001 - Artist name - song title.txt

Where the "Artist name" part come from?

Re: Renaming Files

Posted: 23 Mar 2018 17:55
by tlm2408
I need to change the text file to have exactly the same name as the mp3. So if I have:

001 - Van Halen - Panama.mp3
01 - Panama.txt
002 - Alice Cooper - Poison.mp3
02 - Poison.txt
003 - Iron Maiden - Run To The Hills.mp3
03 - Run To The Hills

it will become
001 - Van Halen - Panama.txt
002 - Alice Cooper - Poison.txt
zz - 003 - Iron Maiden - Run To The Hills.txt

So if I have:
01 - Panama (with no file extension) I need it to be changed to:
zz 001 - Van Halen - Panama.txt

I hope this makes sense.

Re: Renaming Files

Posted: 27 Mar 2018 04:12
by Samir
So a couple of questions to clarify some things.

If a file is without an extension, you want it to start with "zz"?

If the file has a .txt, extension, it should be the same name as the mp3, except with a txt extension, correct?

Re: Renaming Files

Posted: 29 Mar 2018 10:48
by tlm2408
Yes, that is what I'm looking for

Re: Renaming Files

Posted: 30 Mar 2018 08:46
by kwsiebert
Does every mp3 file start with a 3 digit number?
Does every text file start with a 2 digit number?
Do any artist names or song titles contain a - or . character?
Do any artist names or song titles contain any other special characters?
Are there any files in the directory other than the types you have told us about?

If the answers are yes, yes, no, no, and no, you may be able to do it in just two lines:

Code: Select all

for %A in ("?? - *") do ren "%A" "0%A"
for %A in ("??? - *.mp3") do for /f "tokens=1-3 delims=-" %B in ("%~nA") do ren "%B-%D.txt" "%B-%C-%D.txt" && ren "%B-%D." "zz %B-%C-%D.txt"
To use this in a batch file instead of just the command line, replace each % with %%.

If there are any file names that don't match the naming patterns you provided, or that do contain special characters, strange results could occur. I obviously can't test it, since I don't have your full file list, but I would replace the ren commands with echo and/or redirect it to a text file first and preview the results.

Re: Renaming Files

Posted: 30 Mar 2018 15:57
by tlm2408
Thank you very much kwsiebert, that works great!!!!