Skip to main content

Topic: Changing the default "illegal character" replacement charact (Read 9671 times) previous topic - next topic

0 Members and 1 Guest are viewing this topic.
  • golphcart
  • [*][*]
Changing the default "illegal character" replacement charact
Okay, this may be anal, but I hate the _ (underscore).  It's evil and I never want to see it in my filenames.  It's ugly.  My opinion, of course.  Right now, I am using a conjuction of $and() and $replace() to change illegal characters like ? ! > < (there are others I'm sure, but those are the ones I usually see in my tags) to a hyphen.  I know this has got to be some kind of default, probably one that is easy to change, but I cannot find it  (when you simply rename from file tags with these characters in it, it automagically changes them to the underscore).  What I would like is to automagically change these to a - (hyphen).  Is this possible?

Please and thanks.

golphcart.

EDIT:  Okay, so the $replace() doesn't seem to work..., I thought it used to, but I guess I haven't done it in a while.  It shows that it works in the preview line, when you edit a file naming scheme, but when you select the file naming scheme in the output file name format drop-down menu, the preview shows an underscore.  Also illegal characters I actually see, after a more careful look are:
:  /  <  ?
  • Last Edit: 13 September, 2006, 05:46:46 PM by golphcart

  • golphcart
  • [*][*]
Changing the default "illegal character" replacement charact
Reply #1
Can someone read what I wrote in the 'EDIT' and comment on it, please.  Even just saying I'm an anal f*ckstain would be grand.

Seriously, though, the $replace() method USED to work; what am I missing?

- teh golphcart.
  • Last Edit: 16 September, 2006, 01:38:45 AM by golphcart

  • david_dl
  • [*][*][*][*][*]
Changing the default "illegal character" replacement charact
Reply #2
The illegal characters for a windows filename are:
Code: [Select]
\ / : * ? " < > |

  • Cosmo
  • [*][*][*][*][*]
Changing the default "illegal character" replacement charact
Reply #3
I'm not sure I completely understand what you're doing. Have you tried using the $replace() function to replace underscores instead of the illegal characters?

exa: $replace(%artist% - %title%,_,-)

It works for me... but again, I aint sure I understandz you.

[ edit ~ it doesn't work in the preview, but the filename comes out right ]
  • Last Edit: 16 September, 2006, 03:44:05 AM by Cosmo

  • golphcart
  • [*][*]
Changing the default "illegal character" replacement charact
Reply #4
I'm not sure I completely understand what you're doing. Have you tried using the $replace() function to replace underscores instead of the illegal characters?

exa: $replace(%artist% - %title%,_,-)

It works for me... but again, I aint sure I understandz you.

[ edit ~ it doesn't work in the preview, but the filename comes out right ]


Nope.  You don't.  But that's fine.  I have files which I tagged using illegal characters (i.e. cannot be used in a windows filename) in various tag fields.  Thus when I try to rename from tag fields, foobar automatically changes these illegal characters (see david_dl's post) with an underscore.  I would like them to be replaced with a hyphen.  That's the dealio.

Hope the following pic will explain what I cannot in words:



Thanks.

- teh golphcart.

To clarify what is in the picture:

I did NOT edit the file naming script, just opened it for your viewing pleasure.

I DID test the file naming script by using on the files selected, and in fact the underscore was NOT removed.  (As in the OUTPUT FILE NAME preview, NOT the FILE NAMING SCRIPT preview)

I DID try moving the files to another harddrive and back again using this script. (dunno what this would affect, but I did it)

I DID check to make sure these files are not read-only.

I DID try changing the filenaming script, using it, then change back to the filenaming script in the picture, and using it; same result occured.  (again, dunno what this would affect, but I did it)

  • Cosmo
  • [*][*][*][*][*]
Changing the default "illegal character" replacement charact
Reply #5
I guess I should have tried more illegal characters. I only used ''\'' as a test, and it worked. 

try this one:
Code: [Select]
$replace($replace($replace($replace($replace($replace($replace($replace(%artist% - %album% - %tracknumber% - %title%,:,-),*,-),?,-),",-),<,-),>,-),|,-),_,-)
the following will replace underscores in existing filenames:
Code: [Select]
$replace(%filename%,_,-)

EDIT: after gob added further clarity to the issue (thanks!), I now see that the first script can be shortened a little more:
Code: [Select]
$replace($replace($replace($replace($replace($replace(%artist% - %album% - %tracknumber% - %title%,*,-),?,-),",-),<,-),>,-),_,-)
...or maybe there's an altogether better way...?

EDIT.2: lol, shame on me for not RTFM. After gfngfgf's insightful tip :
Code: [Select]
$replace(%artist% - %album% - %tracknumber% - %title%,*,-,?,-,",-,<,-,>,-,_,-)
...though you'll probably want to remove things like ''?'' instead of replace. Anyhow, you get the idea!
  • Last Edit: 17 September, 2006, 02:41:28 AM by Cosmo

  • gob
  • [*][*][*][*]
Changing the default "illegal character" replacement charact
Reply #6
i understand what you’re talking about. when using scripts to move and rename files, the $replace() function properly works with ?, <, >, *, and " for both the previews and the actual renaming of the files. but not with /, \, |, or :. when using the latter illegal chars, the preview boxes in the file naming scheme windows will show that $replace(%tag%,'/',-) works, however, the preview box in the move, rename, or copy files window will show that the / is still being replaced with _ and it will be renamed this way also.

you can however use $replace(%tag%,_,-) to replace the /, \, |, and : chars with a string of your choice, just change the - in that script with the string you want.

also, when using $replace(%tag%,_,-), the preview boxes in the file naming scheme windows will show that the / has not been replaced with a -. but the move, rename, or copy files window will, and the file will be renamed this way.

i agree the $replace() function should work with whatever chars you throw at it, and have them properly handled before they are modified for correct filenames.


here is the script that i use to move and rename my albums
Code: [Select]
$if(%artist%,$trim($replace($replace($replace($replace($replace($replace(%artist%,?,),<,{),>,}),'"',''),*,+),_,-)),unknown artist)/[%date%'.' ]$if(%album%,$trim($replace($replace($replace($replace($replace($replace(%album%,?,),<,{),>,}),'"',''),*,+),_,-)),unknown album)/$if(%discname%,$trim($replace($replace($replace($replace($replace($replace(%discname%,?,),<,{),>,}),'"',''),*,+),_,-))'/',[%disc%.])[$left(%tracknumber%,2). ]$trim($replace($replace($replace($replace($replace($replace(%title%,?,),<,{),>,}),'"',''),*,+),_,-))
  • Last Edit: 17 September, 2006, 01:07:23 AM by gob

  • gfngfgf
  • [*][*][*][*][*]
Changing the default "illegal character" replacement charact
Reply #7
slightly OT, but the $replace() function can take more than three arguments, so this:

Code: [Select]
$replace($replace(%title%,?,-),*,-)

is equivalent to:

Code: [Select]
$replace(%title%,?,-,*,-)

It just looks nicer, really.

  • gob
  • [*][*][*][*]
Changing the default "illegal character" replacement charact
Reply #8
slightly OT, but the $replace() function can take more than three arguments, so this:

Code: [Select]
$replace($replace(%title%,?,-),*,-)

is equivalent to:

Code: [Select]
$replace(%title%,?,-,*,-)

It just looks nicer, really.


nice. thanks for that info.

  • golphcart
  • [*][*]
Changing the default "illegal character" replacement charact
Reply #9
Thanks for all the input, guys.  Really helpful.  But I am still wondering what I can do about the ':' & the '/' There is quite a few of them in album and title tags, and I really would like to replace them with a hyphen instead of an underscore.

Also, going back to my original post:

Is there any way to just make the default illegal character replacement a hyphen instead of an underscore?  This would void all the messy replace issues, entirely.
  • Last Edit: 17 September, 2006, 04:37:05 PM by golphcart

  • Yotsuya
  • [*][*][*][*][*]
Changing the default "illegal character" replacement charact
Reply #10
Try using $char(58) instead of :, and $char(47) instead of /

$replace(%title%,$char(58),-,$char(47),-)

  • golphcart
  • [*][*]
Changing the default "illegal character" replacement charact
Reply #11
same deal, yotsuya.  it works in the file naming script preview, but not the output file name preview nor the actual output file name.

thanks though.

  • Cosmo
  • [*][*][*][*][*]
Changing the default "illegal character" replacement charact
Reply #12
I am still wondering what I can do about the ':' & the '/'

In my testing, I put all of the above mentioned illegal characters ( \ / : * ? " < > | ) into tags, and they were all converted to hyphens in the file name. What version of foobar2000 do you use?

I also wonder if windows version / settings could have effect?
  • Last Edit: 17 September, 2006, 04:59:31 PM by Cosmo

  • golphcart
  • [*][*]
Changing the default "illegal character" replacement charact
Reply #13
What version of foobar2000 do you use?


v0.9.3.1

I also wonder if windows version / settings could have effect?


windows xp pro sp1

settings?  not sure what you mean.

also, I don't think it is a windows issue (as I've stated in previous posts, I used to use $replace() with no problems), but then again, I can't remember specifically which characters I was replacing.  It might not have been one of the four that seems to cause problems (from gob's post  : / \ | ).

for now I have used your solution:

$replace(%filename%,_,-)

Thanks for all the help.  I appreciate it.
  • Last Edit: 18 September, 2006, 12:22:50 AM by golphcart

  • Cosmo
  • [*][*][*][*][*]
Changing the default "illegal character" replacement charact
Reply #14
It also works in 0.9.3.1 for me. (same OS)

By ''settings'', I meant something like code page (character encoding). Wild guess.

Good luck!

  • golphcart
  • [*][*]
Changing the default "illegal character" replacement charact
Reply #15
This is kind of repetitive but I'm going to post it anyways:

relevant tag info:
ALBUM=A Girl Like Me  \ / : * ? " < > |

file naming scheme:
$replace(%album%,\,1,/,2,:,3,*,4,?,5,",6,<,7,>,8,|,9)

file naming scheme preview:
A Girl Like Me  1 2 3 4 5 6 7 8 9

output file names preview:
A Girl Like Me  _ _ _ 4 5 6 7 8 _

say I actually ran this script to rename this to %album%.mp3
now I run a new file naming script:
$replace(%filename%,_,-)

my output is now:
A Girl Like Me  - - - 4 5 6 7 8 -.mp3

so basically the $replace() function is useless for illegal characters' numbered 1 (\), 2 (/), 3 (:) and 9 (|)

Cosmo:

not sure really what you are asking (basically I am not exactly sure what a code page - character encoding is) but I did run charmap.exe to find out the corresponding hexadecimal codes for the troublesome characters, and I searched google for 'how to find windows code page' and after some links found one that had the same hexadecimal codes for the troublesome characters.

I use two fonts in foobar:
MS Sans Serif 8pt for playlist switcher
Verdana 10pt for playlist tabs

both had equal hex.dec. values for illegal chars in charmap
charmap hex.dec. values for illegal chars matched website
(http://www.microsoft.com/globaldev/reference/sbcs/1250.mspx)
I must say I have absolutely no idea if this is the code page that my comp uses but I assume it is.  I live in the US and have no idea how to change my code page, and I dare say that this is the default.

codes:
\ 0x5c or $char(92)
/ 0x2f or $char(47)
: 0x3a or $char(58)
| 0x7c or $char(124)

also I checked the hyphen in both fonts for charmap and the website.
code:
- 0x2d or $char(45)

I guess that's a summary, of sorts.

- teh golphcart.

EDIT: goddamn smilies. :)
  • Last Edit: 18 September, 2006, 02:50:18 AM by golphcart

  • Cosmo
  • [*][*][*][*][*]
Changing the default "illegal character" replacement charact
Reply #16
I'm sorry about the confusion, I didn't mean to make it sound like I was asking you for your OS info, I was just wondering aloud. I don't know much about character encoding stuff either (and thus I could be way off base), but it seems that since the $replace() function is acting differently on our systems (in foobar of the same version), then perhaps the problem is outside of foobar. (I'm not aware of any settings within foobar that would cause this discrepancy.) Or maybe it's not the system, but something within the files?

  • kjoonlee
  • [*][*][*][*][*]
Changing the default "illegal character" replacement charact
Reply #17
The characters in \ / : * ? " < > | are all part of 7bit ASCII, so there shouldn't be any codepage problems with 8bit extensions to ASCII.

Maybe Cosmo uses NTFS and golphcart uses FAT32?

  • golphcart
  • [*][*]
Changing the default "illegal character" replacement charact
Reply #18
NTFS here.

more specifically...

one volume is NTFS basic and the other is NTFS dynamic
  • Last Edit: 18 September, 2006, 04:20:50 AM by golphcart

  • gob
  • [*][*][*][*]
Changing the default "illegal character" replacement charact
Reply #19
slightly OT, but the $replace() function can take more than three arguments, so this:

Code: [Select]
$replace($replace(%title%,?,-),*,-)

is equivalent to:

Code: [Select]
$replace(%title%,?,-,*,-)

It just looks nicer, really.



after modifing all my scripts that used multiple replace functions, i found out using $replace(%title%,' To ',' to ',' A ',' a ',' On ',' on ') will not always give the same result as $replace($replace($replace(%title%,' To ',' to '),' A ',' a '),' On ',' on ')

heres an example: if the title is "Your Pussy's Glued To A Building On Fire"
$replace(%title%,' To ',' to ',' A ',' a ',' On ',' on ') will produce
"Your Pussy's Glued to A Building on Fire"
$replace($replace($replace(%title%,' To ',' to '),' A ',' a '),' On ',' on ') will produce
"Your Pussy's Glued to a Building on Fire"

this is very odd and confusing behaviour..

  • pepoluan
  • [*][*][*][*][*]
Changing the default "illegal character" replacement charact
Reply #20
heres an example: if the title is "Your Pussy's Glued To A Building On Fire"
$replace(%title%,' To ',' to ',' A ',' a ',' On ',' on ') will produce
"Your Pussy's Glued to A Building on Fire"
$replace($replace($replace(%title%,' To ',' to '),' A ',' a '),' On ',' on ') will produce
"Your Pussy's Glued to a Building on Fire"

this is very odd and confusing behaviour..

My guess is the multi-parameter $replace works like this:
Code: [Select]
Your Pussy's Glued To A Building On Fire
0123456789012345678901234567890123456789
0         1         2         3

* It searches for anything resembling the searched-for pattern, i.e. ' To ', ' A ', and ' On ' (note the spaces on left and right.
* It finds ' To ' at position 18.
* It replaces ' To ' with ' to ', and shifts the pointer to after the end of the found pattern, i.e. the pointer is now pointing at position 22, which means that the current pattern is 'A ' not ' A ' ( ' A ' is found at position 21).
* It keeps scanning until it finds ' On ' at position 32.
* It replaces ' On ' with ' on ', and resumes at position 36.
*Finish.

CMIIW

I'm sleepy, going offline, bye!
Nobody is Perfect.
I am Nobody.

http://pandu.poluan.info

  • golphcart
  • [*][*]
Changing the default "illegal character" replacement charact
Reply #21
gob:

I think an easy way to fix that is to ditch the space to the left of the words (all of them).

$replace(%title%,'To ','to ','A ','a ','On ','on ')

Now you don't have the potential for 'overlapping' spaces.  This would still do what you want I think unless you have some word with a capital letter mid-word.  I can't think of a good example so I'll give a bad (but still failing) example:

Dr McTo Eats Butterflies for Breakfast

would be replaced to

Dr Mcto Eats Butterflies for Breakfast

  • gob
  • [*][*][*][*]
Changing the default "illegal character" replacement charact
Reply #22
gob:

I think an easy way to fix that is to ditch the space to the left of the words (all of them).

$replace(%title%,'To ','to ','A ','a ','On ','on ')

Now you don't have the potential for 'overlapping' spaces.  This would still do what you want I think unless you have some word with a capital letter mid-word.  I can't think of a good example so I'll give a bad (but still failing) example:

Dr McTo Eats Butterflies for Breakfast

would be replaced to

Dr Mcto Eats Butterflies for Breakfast


yea, but i dont want any of these words to be replaced unless there is a space in front of them. so multiple replace functions are needed. either way, if it works using 15 replace functions, thats what i will do.

  • golphcart
  • [*][*]
Changing the default "illegal character" replacement charact
Reply #23
Old solution:

$replace(%tag%,\,-,/,-,:,-,*,-,?,,",-,<,-,>,-,|,-)
$replace(%filename%,_,-)

But this did not work when trying to change path based on tags, and was two steps.

New solution:

$replace($replace(%tag%,\,-,/,-,:,-,*,-,?,,",-,<,-,>,-,|,-),_,-)

Now this replaces all the baddies that cannot be replaced normally.

Still brings up the question: Why do these 4 characters not want to be replaced?

  • Ydope
  • [*]
Changing the default "illegal character" replacement charact
Reply #24
This is kind of repetitive but I'm going to post it anyways:

relevant tag info:
ALBUM=A Girl Like Me  \ / : * ? " < > |

file naming scheme:
$replace(%album%,\,1,/,2,:,3,*,4,?,5,",6,<,7,>,8,|,9)

file naming scheme preview:
A Girl Like Me  1 2 3 4 5 6 7 8 9

output file names preview:
A Girl Like Me  _ _ _ 4 5 6 7 8 _

say I actually ran this script to rename this to %album%.mp3
now I run a new file naming script:
$replace(%filename%,_,-)

my output is now:
A Girl Like Me  - - - 4 5 6 7 8 -.mp3

so basically the $replace() function is useless for illegal characters' numbered 1 (\), 2 (/), 3 (:) and 9 (|)


Hi,

sorry to bring this old thread back, but this is exactly my problem.

I have some cases where %ALBUM ARTIST% = e.g. "Jim / John" and I want the directory name to look like "Jim & John". When I $replace " / " with " & " it doesn't work but I get "Jim _ John". Just as described above.

So how can I find a solution that does what I want but leaves Album Artists that may already include underscores for whatever reason in order. I don't want to replace every " _ " with " & ".

Any idea? This is really bugging me.

Great thanks in advance,
Y
  • Last Edit: 29 October, 2007, 05:10:06 PM by Ydope