Renaming Files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
tlm2408
Posts: 31
Joined: 01 Aug 2017 01:19

Renaming Files

#1 Post by tlm2408 » 23 Mar 2018 16:21

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.

Aacini
Expert
Posts: 1615
Joined: 06 Dec 2011 22:15
Location: México City, México

Re: Renaming Files

#2 Post by Aacini » 23 Mar 2018 17:44

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?

tlm2408
Posts: 31
Joined: 01 Aug 2017 01:19

Re: Renaming Files

#3 Post by tlm2408 » 23 Mar 2018 17:55

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.

Samir
Posts: 345
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: Renaming Files

#4 Post by Samir » 27 Mar 2018 04:12

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?

tlm2408
Posts: 31
Joined: 01 Aug 2017 01:19

Re: Renaming Files

#5 Post by tlm2408 » 29 Mar 2018 10:48

Yes, that is what I'm looking for

kwsiebert
Posts: 31
Joined: 20 Jan 2016 15:46

Re: Renaming Files

#6 Post by kwsiebert » 30 Mar 2018 08:46

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.

tlm2408
Posts: 31
Joined: 01 Aug 2017 01:19

Re: Renaming Files

#7 Post by tlm2408 » 30 Mar 2018 15:57

Thank you very much kwsiebert, that works great!!!!

Post Reply