Auto Renaming of filenames if duplicated

My way of dealing with duplicates is this:

My naming for files is:

  1. Artist - Title ( for albums )

and

Artist - Title ( for orphan VA's all in one folder(s) )

( if yours is deferent it might not work adjust it as you like )

and i put duplicate numbering at the end of Title like 13. Artist - Title (1) just to match windows naming

So!

  1. first create a column with:

Name: File already exists ( or whatever you like )

Value: $if($eql(%_filename%,$if($if2(%track%,%tracknumber%),[$if2(%track%,%tracknumber%). ],)$if(%title%,$if(%artist%,[%artist% - ],),%artist%)$if(%title%,%title%,)),OK,File already exists)

  1. then go to actions and create 11 GROUPS ( or more if you like ) but don't tick them. ( i put them at the bottom )

The groups should be like this ( or whatever you like ):

File allready exists#Title + ( 1 ) ( and should contain this: )

1 Replace with regular expression

Field: TITLE
Regular expression: \s*(+\s*[0-9]{1,2}\s*)+$
Replace matches with: nothing leave empty

2 Format value

Field: TITLE
Format string: %title% (1) ( change with the appropriate number like 1 in this group )

3 Format value

Field: _FILENAME
Format string: $if(%track%,$num(%track%,1). ,)%artist% - %title%

4 Format value

Field: _FILENAME
Format string: $trim(%_filename%)

File allready exists#Title + ( 2 ) ( enter the same 4 action types changing only the second with the appropriate number like 2 in this group )
File allready exists#Title + ( 3 ) ( enter the same 4 action types changing only the second with the appropriate number like 3 in this group )
File allready exists#Title + ( 4 ) ( enter the same 4 action types changing only the second with the appropriate number like 4 in this group )
File allready exists#Title + ( 5 ) ( enter the same 4 action types changing only the second with the appropriate number like 5 in this group )
File allready exists#Title + ( 6 ) ( enter the same 4 action types changing only the second with the appropriate number like 6 in this group )
File allready exists#Title + ( 7 ) ( enter the same 4 action types changing only the second with the appropriate number like 7 in this group )
File allready exists#Title + ( 8 ) ( enter the same 4 action types changing only the second with the appropriate number like 8 in this group )
File allready exists#Title + ( 9 ) ( enter the same 4 action types changing only the second with the appropriate number like 9 in this group )
File allready exists#Title + ( 10 ) ( enter the same 4 action types changing only the second with the appropriate number like 10 in this group )

File allready exists#Title + clear ( this should contain ):

1 Replace with regular expression

Field: TITLE
Regular expression: \s*(+\s*[0-9]{0,2}\s*)+$
Replace matches with: nothing leave empty

2 Format value

Field: TITLE
Format string: %title%

3 Format value

Field: _FILENAME
Format string: $if(%track%,$num(%track%,1). ,)%artist% - %title%

4 Format value

Field: _FILENAME
Format string: $trim(%_filename%)

Now the first thing i do ( for orphan VA's folders ) is to remove tracknumbers and to convert:

Tag - Filename with
Format string: %artist% - %title% ( no tracknumber because i don't use it for VA folders containing orphans so i can spot the real duplicates ) ( if it is for an album(s) you add tracknumber too but i don't thing you will find a lot )

After a lot of ignore

The first results at the ( File already exists column ) appear and you sort that column.

There they are. You select all the File already exists files and go to the

ACTION TAB AT THE FILE MENU ( NOT THE RIGHT CLICK ACTION MENU )

from the drop down menu you select

File already exists ---> Title + ( 1 )

and your filles should be renamed as

Artist1 - Title (1)
Artist2 - Title (1)

and so on for duplicates only.

If again you have duplicates after applying, that didn't renamed, select them from the column again and

go to

ACTION TAB AT THE FILE MENU ( NOT THE RIGHT CLICK ACTION MENU )

from the drop down menu you select

File already exists ---> Title + ( 2 )

and your filles should be renamed as

Artist1 - Title (2)
Artist2 - Title (2)

and so on for duplicates only.

If you want a clear start in title tags go to

ACTION TAB AT THE FILE MENU ( NOT THE RIGHT CLICK ACTION MENU )

from the drop down menu you select

File already exists ---> Title + clear

and your ( TITLE TAGS not the filenames ) should be renamed as

Title
Title

but you will have complains about duplicates renaming again.

I hope this works for you as it does for me.

It is much faster than it looks.

Use it with a portable Mp3Tag and some copied files for testing it.

Thanks for the suggestion,

at first glance it looks like a potential option, I'll see if it works for my use case and if it can be automated.

I also use AUTOIT to automatically start multiple MP3TAG Actions in sequence once the previous one is completed.

Cheers

The one you have post does not work for me it doesn't start.
Unless i am doing something wrong ( i am not a programmer )
All sounds interesting could you share some?
A fast working Mp3Tag is always a good thing.

Mp3tag must be running.
You should see the autoit script icon in the taskbar once started.
It will automatically end once you exit mp3tag.

Sorry my fault it works perfectly. AMAZING!!! Thank you it's a time saver.

If you test it and you like it and if you can automate it i thing that an auto renaming is very close. Or i hope so.

Glad it works for you as well.

I'll see if I can find time to test your workaround.

adding a simple option to "keep both but rename", like Windows and most apps do, would make things so much easier...

Very nice.
Can you make the script stay always open if i am not asking too much.
Never mind about that solved it.

Just remove this line :

If WinExists("Mp3tag" , "") = 0 Then ExitLoop

Thank you it works fine.

I came up with a better version for my duplicate files. (an update)

The "better" is that you select all the duplicate files and you just keep heating rename ( from the menu actions as i mentioned before ) until everything is renamed with an added number.

So, for this to work you have to:

Remove the 9 out of the 10 GROUPS that are named as:

"File allready exists#Title + ( 1 - 10 )" ( or leave them as a backup ).

Rename the one remaining as:

"File allready exists#Title ( Any title-number plus 1 )"

The action-group should be like this ( or whatever you like ):

File allready exists#Title ( Any title-number plus 1 ) ( and should contain this):

1 Format value

Field: TITLE
Format string: $if($eql(%_filename%,$if(%tracknumber%,%tracknumber%. ,$if(%track%,%track%. ,))$if(%artist%,%artist% - ,)$if(%title%,%title%,)),%title%,$ifgreater($strrchr(%title%,')'),0,$if($eql($strchr($right($left($right(%title%,6),5),4),'('),1),$ifgreater($right($left($right(%title%,5),4),3),99,$replace(%title%,$right($left($right(%title%,5),4),3),$add($right($left($right(%title%,5),4),3),1)),%title% '('1')'),$ifgreater($strrchr(%title%,')'),0,$if($eql($strchr($right($left($right(%title%,5),4),3),'('),1),$ifgreater($right($left($right(%title%,4),3),2),9,$replace(%title%,$right($left($right(%title%,4),3),2),$add($right($left($right(%title%,4),3),2),1)),%title% '('1')'),$ifgreater($strrchr(%title%,')'),0,$if($eql($strchr($right($left($right(%title%,4),3),2),'('),1),$ifgreater($right($left($right(%title%,3),2),1),0,$replace(%title%,$right($left($right(%title%,3),2),1),$add($right($left($right(%title%,3),2),1),1)),),%title% '('1')'),)),)),%title% '('1')'))

2 Format value

Field: _FILENAME
Format string: $if($if(%track%,%track%,%tracknumber%),$num($if(%track%,%track%,%tracknumber%),1). ,)%artist% - %title%

3 Format value

Field: _FILENAME
Format string: $trim(%_filename%)

Now select some duplicates and start renaming.
It can rename from 1 up to 1000.

Some problems that may-will occur are with files like:

Artist - Title part (1)
Artist - Title part (2)
Artist - Title number (99)

witch will become:

Artist - Title part (2)
Artist - Title part (3)
Artist - Title number (100)

but not with files like:

Artist - Title part 1
Artist - Title part 2
Artist - Title number 99
Artist - Title part (1024)
Artist - Title year (2023)

witch will become:

Artist - Title part 1 (1)
Artist - Title part 2 (1)
Artist - Title number 99 (1)
Artist - Title part (1024) (1)
Artist - Title year (2023) (1)

General speaking if you have files with numbers from 1-999 at the end of the title like Title (1),Title (34),Title (99),Title (999),Title (133) that you don't want to miss then be careful.

I haven't test it extensively with allot variety of files but i think it should work fine.

Use it with a portable Mp3Tag and some copied files for testing it.

Ok. I found a problem.
That is when the files are in different folders and you want to move them in a common folder mp3tag will give you a duplicate warning and if you try to rename them with the above solution (the safe one) and then move them they won't get renamed because the filenames and the tags match and they are in different folders.

So you must make another action-group (duplicate the above) that should be like this ( or whatever you like ):

File allready exists#Title ( Any title-number plus 1 in different folders )

and replace the (Format string:) with this:

Format string: $if($eql(%_filename%,$if(%tracknumber%,%tracknumber%. ,$if(%track%,%track%. ,))$if(%artist%,%artist% - ,)$if(%title%,%title%,)),$ifgreater($strrchr(%title%,')'),0,$if($eql($strchr($right($left($right(%title%,6),5),4),'('),1),$ifgreater($right($left($right(%title%,5),4),3),99,$replace(%title%,$right($left($right(%title%,5),4),3),$add($right($left($right(%title%,5),4),3),1)),%title% '('1')'),$ifgreater($strrchr(%title%,')'),0,$if($eql($strchr($right($left($right(%title%,5),4),3),'('),1),$ifgreater($right($left($right(%title%,4),3),2),9,$replace(%title%,$right($left($right(%title%,4),3),2),$add($right($left($right(%title%,4),3),2),1)),%title% '('1')'),$ifgreater($strrchr(%title%,')'),0,$if($eql($strchr($right($left($right(%title%,4),3),2),'('),1),$ifgreater($right($left($right(%title%,3),2),1),0,$replace(%title%,$right($left($right(%title%,3),2),1),$add($right($left($right(%title%,3),2),1),1)),),%title% '('1')'),)),)),%title% '('1')'),%title%)

This will rename them even if the filenames and tags match. (dirty solution i know, so you must be careful and first sort the path column and then select and rename the ones that are not in the destination folder. Repeat for leftovers step by step)

Also rename the (previous-above-original) one to:

File allready exists#Title ( Any title-number plus 1 in the same folder )

I hope it works fine!

it appears that, despite al RegEx coding you can do in MP3Tag, it does not accommodate this

however, i am surprised if you are relying just on MP3Tag for all your music (or other) file handling!

personally, i use a number of relevant utilities to help manage file naming/file dup issues on a constant daily basis that are just invaluable

the first and most relevant to you here is a massively useful FREE! app Bulk Rename Utility (BRU). as



time as gone on, i have found more and more ways i could manipulate file names (its main, only, limitation - currently - is that it does NOT edit Tags, only File Name, although i am suggesting to dev that he should do that, and then rename and remarket the existing app.)

and, although you can use RegEx within this app, i never have, because, unlike MP3Tag, all the many many multiple ways to manipulate the file names (and ext) string have already been pre-coded for you

hopefully attached screenshot ...

even now i find new ways to check/fix issues with music and other file names

the next relevant extremely useful utility i would recommend you get to know and love is ALLDUP

apart from the many many different ways of identifying 'dups', what may be of interest is its post-dup handing - which includes both moving to a selected folder, AND renaming.

again, hopefully attached screenshot

there are of course many other useful apps, but i should prob shout out Beyond Compare - which has probably saved me years of time since i started to use it sooooooo long ago, and which could well be useful in this context.

I am a long time user of (BRU) and many other utilities (StExBar and so on) but i personally don't use them for music files (except for some special occasions). If you like it this way its ok with me.

I think that anything else than (foobar2000 <-> Mp3tag <-> Everything) combination is a waste of time (speaking for audio files only). They complete one an other and yes i haven't use any other software from the time i found them (i don't even remember when).

Maybe it's because i hate using many programs for doing one thing if i can do it from only one.

Then i don't trust a program to delete a duplicate file for me without listening the song for it's quality or compare bit rates, lengths etc.

I don't know how deep you have gone with Mp3Tag but i thing everything is there.

Except duplicate renaming. :slight_smile:

By the way. Have you tested my solution;