Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: File Rename problem with $replace() (Read 3524 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

File Rename problem with $replace()

I'm using this string to rename my files -

%track% - $replace(%title%,'\',,'/',,':',,'*',,'?',,'"',,'<',,'>',,'|',)

to get rid of illegal filename characters.  But it's not working correctly.  In the window where you edit the rename strings, the filename preview is correct.  However once I 'OK' back the the main file renamer window (where you can hit run) the file preview is different and many illegal characters are replaced by underscores.  I noticed this happening with / and : specifically, possibly others.

It's not just a preview bug, cause running it will create filenames with underscores.  Can anyone else confirm this or propose a solution?

 

File Rename problem with $replace()

Reply #1
Illegal characters are replaced by underscores when a field is evaluated, for example:

TITLE = ab:cd\ef

$replace(%title%,:,-)
$replace(ab_cd_ef,:,-)
ab_cd_ef

This is by design, and according to the developer it's not going to change. Yes, the drawback is that you cannot define your own replacements, and that you will always end up with special characters being replaced by underscores in your filenames, unless you filter those out by a $replace statement.

However, the advantages are that the default naming schemes can be kept simple and that the user isn't faced with adding a complicated $replace-expression to any scheme he creates, and of course that illegal characters are absolutely prevented from causing unexpected results, like unintentionally created subfolders or even a denial of the renaming.

It has been suggested by some users to perform the replacement after any titleformatting. But if you consider a scheme that doesn't replace special characters, like "%artist%\%title%", with ARTIST="Whoever" and TITLE set like in the above example, you would end up with the filename "Whoever\ab:cd\ef".

If you want to replace special characters at this point, how should the software reliably determine which backslash is intentional, and which backslash should be removed? This is not possible, and thus it's a good idea to solve the problem as demonstrated above.

Quote
It's not just a preview bug (...)

No, what is working incorrectly here is indeed the preview area in the window where you edit the schemes.

This is known, but I do not know if or when it's going to be fixed.

File Rename problem with $replace()

Reply #2
Thanks for the reply.  It all makes sense, unfortunately  I'll just replace the underscores after the fact.  It would be nice to be able to define the replacement character(s) somewhere in the preferences however.

File Rename problem with $replace()

Reply #3
Illegal characters are replaced by underscores when a field is evaluated, for example:

TITLE = ab:cd\ef

$replace(%title%,:,-)
$replace(ab_cd_ef,:,-)
ab_cd_ef

This is by design, and according to the developer it's not going to change. Yes, the drawback is that you cannot define your own replacements, and that you will always end up with special characters being replaced by underscores in your filenames, unless you filter those out by a $replace statement.

Upon further testing, actually by accident, this is not as straight forward as you say.

I used a test mp3 and set the track title in the id3 tag to

\/:*?"<>|

all the illegal characters.  Then in my file copy formatting, used

$replace(%title%,'_','z')

What I should have ended up with was a file named

zzzzzzzzz.mp3

since the filename should have been evaluated as

$replace(_________,'_','z')

as you stated above.  What I actually got was

zzz_____z.mp3

Strange no?  It seems that only

\/:|

are replaced before the string is evaluated and

*?"<>

are replaced after titleformatting, as a final correction.  Thoughts?

File Rename problem with $replace()

Reply #4
Bah, shame about that. I really looked forward to them fixing this bug, and now I get to know that they never will. Foobar is the best thing that ever happened to me and my music collection, and this was its only drawback. Serious too, since I'm practically OCD when it comes to organizing things perfectly.

Underscores is not perfect.

Is there a plugin of any sort that does the same, and allows replacing of illegal characters? If not, then someone should seriously consider making one.