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: Illegal filename characters replacement (Read 13402 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Illegal filename characters replacement

I remember chars like ":" were replaced with "_" in previous versions. In some of the newer versions (I cannot tell which one) it was changed to "-". Is there an option to choose which symbols to substitute? Because I'd like to, for example, change ":" to " -" (with a space).

Illegal filename characters replacement

Reply #1
You can always create your own namingschemes. Using the $replace() function to replace whatever you want. For example: $replace(%filename%,_,-) or $replace(%filename%,:,-)

Illegal filename characters replacement

Reply #2
You can always create your own namingschemes. Using the $replace() function to replace whatever you want. For example: $replace(%filename%,_,-) or $replace(%filename%,:,-)


No you can't.

Quote from: the foobar2000 FAQ link=msg=0 date=
Why can't I use $replace() to create custom substitution schemes for characters that can't be used in file names?

Invalid file name characters - such as slashes or backslashes - are replaced before metadata originating from the file is processed by title formatting functions. This is necessary to allow slash or backslash characters placed by you in your file name formatting pattern to be interpreted as path delimiters without the side effect of each slash contained in metadata fields included in your file name formatting pattern being interpreted as a path delimiter as well.


There was a longer thread I saw on here before about this, but I have to apologize 'cause I can't seem to find it now. I would like to see this be configurable in the future, though, because this behavior causes issues for me. I used to always replace invalid characters with an underscore when renaming files, and when I re-tagged them using masstager I could search for "_" to find every invalid character I needed to reinsert. Searching for "-" is a lot more complicated, though, 'cause it's a frequently used character, and now I have to spend twice as long on each search result trying to figure out if I'm looking at an "actual"-dash or a "placeholder"-dash. Not a big deal when I'm dealing with a few tracks, but when I'm re-tagging my entire collection after I make a change to my file sorting scheme it's a drag.

-Devin.
O Agatha, you are tiresome.

Illegal filename characters replacement

Reply #3
maybe you could try mp3tag if you don't mind installing another program. that has an option for replacing illegal characters in filenames. check out the $validate function on this help page.

http://help.mp3tag.de/en/main_scripting.html

Illegal filename characters replacement

Reply #4
Quote
You can always create your own namingschemes. Using the $replace() function to replace whatever you want. For example: $replace(%filename%,_,-) or $replace(%filename%,:,-)

No you can't.


When for example you have an album called XXX: volume 1, you can use $replace(%album%,:,-) in the namingscheme.
I tested with $replace([%discnumber%.]%tracknumber%. %artist% - %title%,:,-,/,-) in the filenamingpattern and that works.

Illegal filename characters replacement

Reply #5
That seems to apply only to /, e.g. $replace(%filename%,:,-) works.
Full-quoting makes you scroll past the same junk over and over.

Illegal filename characters replacement

Reply #6
That seems to apply only to /, e.g. $replace(%filename%,:,-) works.


Replacing ":" with "-" is the hardcoded substitution scheme. If I do $replace($meta(album),:,_) most anywhere in foobar2000, it works the way I want it to. If I try it in File Operations > Move to..., however, it doesn't. Ditto for replacing "/" with anything besides a dash. If I'm overlooking something, though, do let me know. (I am using 0.9.6.5 as well, so maybe this behavior has been modified in the most recent release.)

-Devin.

Edit: here is the previous thread about the behavior
O Agatha, you are tiresome.

Illegal filename characters replacement

Reply #7
Here's all the hardcoded rules:

http://wiki.hydrogenaudio.org/index.php?ti...ions#Usage_Tips
Quote
Beginning in 0.9.6.4, symbols which are invalid in folder and file names such as / \ |: get replaced by a -, * gets replaced by x, " gets replaced with '', and ? < > get replaced by an _.
This was changed because it was believed to be better than making all illegal characters underscores. 

I honestly can't think of a good reason to make this user customizable.
elevatorladylevitateme

Illegal filename characters replacement

Reply #8
I honestly can't think of a good reason to make this user customizable.


I backup all of my tag data in my file-naming scheme, so if I ever botch the tag data on a track I can revert to what I had before by using a custom masstagger script. I also use last.fm, so I'm picky about the way my tracks are ultimately tagged. If I have a track called "11:11" (clearly a time), changing it to "11-11" isn't satisfactory, and it's a hard change to reverse for the reasons I laid out earlier in this thread (namely, the dash being such a prominent, *legitimate* character in filenames). I understand I might be in the minority here, but I would like to see foobar2000 respect filenaming/tagging fidelity the same way it does audio fidelity. This, from my view, is a step backwards.

-Devin.
O Agatha, you are tiresome.

Illegal filename characters replacement

Reply #9
Well, no matter what you want to do a : can't be stored in a file name; it's a limitation of Windows.

Trying to exactingly backup tag data in filenames is honestly just a pretty bad idea, and at best a corner case.
elevatorladylevitateme

Illegal filename characters replacement

Reply #10
Trying to exactingly backup tag data in filenames is honestly just a pretty bad idea, and at best a corner case.


Oh, I'm sure I represent a minority view here.  I haven't had many issues since I started using foobar2000 exclusively, but I have certainly had cases where I went to open a large portion of my collection with some new program, only to discover that it had made some radical change to either my tagging or naming scheme without prompting me. That's why I backup my tag data the way I do: if a program alters either my tags or my file names, I can use the other to reverse that change. It's more work than is arguably worth it, but I don't think it's a "bad idea."

-Devin.

Edit: Admittedly, the Windows file naming limitations aren't going anywhere, but I preferred the old way foobar2000 dealt with them, and some degree of compromise/configurability would be preferable to the current hard coded method... even if it's a toggle buried in the advanced options somewhere. For the average user, the new method probably IS better, just not for me.
O Agatha, you are tiresome.

Illegal filename characters replacement

Reply #11
Replacing ":" with "-" is the hardcoded substitution scheme.

Full-quoting makes you scroll past the same junk over and over.

Illegal filename characters replacement

Reply #12
Son of a . . . I just tried it again and now it works. I swear I double-checked before posting in this thread yesterday, and again this morning.  Now I'm curious what I was doing wrong before, but yeh false alarm. Sorry 'bout that.

-Devin.
O Agatha, you are tiresome.

Illegal filename characters replacement

Reply #13
I would like to see custom replacement rules too, because I have my own. For example / can be replaced by ∕ in file names.
At least all automatic replacements should be done after processing the File Name Pattern:
- For example the colon seems to be replaced after that because I can still replace it myself in the naming pattern, but:
- The slash seems to be replaced even before that: Using %title% in the File Name Pattern doesn't really includes the title, but the title where the slash / has been replaced by -. This prevents me from replacing it manually by e.g. ∕.

Re: Illegal filename characters replacement

Reply #14
I would like to see custom replacement rules too, because I have my own. For example / can be replaced by ∕ in file names.
At least all automatic replacements should be done after processing the File Name Pattern:
- For example the colon seems to be replaced after that because I can still replace it myself in the naming pattern, but:
- The slash seems to be replaced even before that: Using %title% in the File Name Pattern doesn't really includes the title, but the title where the slash / has been replaced by -. This prevents me from replacing it manually by e.g. ∕.
Ugh. Such a mess...

Re: Illegal filename characters replacement

Reply #15
Well, no matter what you want to do a : can't be stored in a file name; it's a limitation of Windows.

Old thread bump I see but did want to add that there are some decent Unicode alternatives.

Can anyone see the difference between this꞉ example colon and this: one?

The former is the Unicode replacement and works perfectly in Windows filenames.

Re: Illegal filename characters replacement

Reply #16
I would like to see custom replacement rules too, because I have my own. For example / can be replaced by ∕ in file names.
At least all automatic replacements should be done after processing the File Name Pattern:
- For example the colon seems to be replaced after that because I can still replace it myself in the naming pattern, but:
- The slash seems to be replaced even before that: Using %title% in the File Name Pattern doesn't really includes the title, but the title where the slash / has been replaced by -. This prevents me from replacing it manually by e.g. ∕.
Ugh. Such a mess...
This replacement nonsense is hilariously inconsistent. It's even applied when I try to add "/" on the numpad as a hotkey (it becomes -), but not for "*". But there's no way to call this function manually. And foobar passes these characters without doing anything with them via foo_run.

Re: Illegal filename characters replacement

Reply #17
Such a pity that tags are altered before they are even available for replacement.
I wanted to replace all illegal Windows file name characters with their fullwidth Unicode character, which is accepted in file names.

Code: [Select]
$replace(%album%,",",<,<,>,>,?,?,*,*,/,/,:,:,\,\,|,|)
(I tried with or without quotes, typewriter apostrophes, with no success)

(Normally, I don’t have any more " and ' in my tags, since these are typewriter characters and we should use typographic characters “ ” ’, which have the extra advantage to be allowed in file names.)

But foobar2000 steals these characters */:\| before they can be caught by $replace(). However, it doesn’t steal <>?", which can be replaced.

What the heck?

Re: Illegal filename characters replacement

Reply #18
But foobar2000 steals these characters */:\| before they can be caught by $replace(). However, it doesn’t steal <>?", which can be replaced.

This is strange, I have a replace with
<,‹,>,›,*,∗,?,¿
and it has worked for quite a while and still does.

Re: Illegal filename characters replacement

Reply #19
Actually, the context where you use the $replace() function is important. The same code
Code: [Select]
$replace(%album%,",",<,<,>,>,?,?,*,*,/,/,:,:,\,\,|,|)
as a column replacement works, but it doesn’t in the Preferences / Display / Album art.

This is somewhat consistent with the wiki says that some characters are automatically replaced, but it appears that not all those characters are stolen in this particular setting.

Re: Illegal filename characters replacement

Reply #20
Just a side remark, if you would replace the characters in the actual tags (with Masstagger) I think it would always work. To me the auto-replace in filenames is OK.
In theory, there is no difference between theory and practice. In practice there is.

Re: Illegal filename characters replacement

Reply #21
Just a side remark, if you would replace the characters in the actual tags (with Masstagger) I think it would always work. To me the auto-replace in filenames is OK.

Yes, searching for "/" will match the full-width character also. So if you do replace it in tags ...

... then it might possibly cause issues to other applications. But maybe not so much if this is due to some Windows functionality.

Re: Illegal filename characters replacement

Reply #22
... then it might possibly cause issues to other applications.
Yes, that’s the very reason I wouldn’t workaround by replacing the actual tags, where all characters are authorised. It would be more difficult to type for a search for such tags on my audio player on my smartphone.

Re: Illegal filename characters replacement

Reply #23
... then it might possibly cause issues to other applications.
Yes, that’s the very reason I wouldn’t workaround by replacing the actual tags, where all characters are authorised. It would be more difficult to type for a search for such tags on my audio player on my smartphone.
I think you are right, it would be annoying if I needed it. A possible solution: Populate <mydirname> and <myfilename> tags.

A better solution would be for fb2k to fix it, but it could be complicated; fb2k cannot just wait 'til the end before replacing "/", because then your directory separator will be gone too.

 

Re: Illegal filename characters replacement

Reply #24
If you are brave you can test my Renamer component that allows defining custom rules for reserved character replacement. It's not as polished as File Operations and all its configuration has to be pre-set on the preferences page:


Note that this doesn't move files from one directory to another, it actually renames all the paths where needed.

The tool can be found under Utilities context menu. It will first show a preview of the results with all changes listed at the top and empty target names for tracks where there's nothing to do. The actual renaming is running without progress bar and can take a while if you have many playlists. It has to do some extra work to keep track of playlist changes due to its dir-by-dir operation.

Edit: I just noticed the ending dot MS says shouldn't be used indeed shouldn't be used. I had renamed my library and couple of albums received the dot. Both Explorer and foobar2000 fail to access the dirs now. A new version that always filters away the a dot from path has been posted.