HydrogenAudio

Hosted Forums => foobar2000 => General - (fb2k) => Topic started by: Tigermess on 2012-04-20 20:34:11

Title: Replacing slash in filename?
Post by: Tigermess on 2012-04-20 20:34:11
I'd like to replace forward slash '/' which is in the TITLE, to be presented in filename otherwise (eg. like ampersand '&' or colon ','). I use File Operations dialog but can't force foobar2000 to replace it with anything else than short dash '-'. I am trying string like
Code: [Select]
$replace(%title%,/,)
, surronding slash with different quotes, preceding it with other slashes, writing it as $char(i-already-forgot-the-number) but without success. Did I do something wrong? Or is it hardcoded? :-(
Title: Replacing slash in filename?
Post by: derty2 on 2012-04-20 23:24:01
$replace(%title%,'/',,)
all slashes found in %title% tag will be removed and replaced by nothing.

$replace(%title%,'/',,'&',,)
all slashes and ampersands found in %title% tag will be removed and replaced by nothing.

$replace(%title%,'/','&')
all slashes found in %title% tag will be replaced by ampersand.

$replace(%title%,'///','&','//','&','/','&')
all triple slashes and double slashes and single slashes found in %title% tag will be replaced by single ampersand.
Title: Replacing slash in filename?
Post by: Tigermess on 2012-04-22 01:40:20
Hi, thanks, I tried the strings you sent, unfortunately it doesn't work :-( Does it work for you in File Operations?
Title: Replacing slash in filename?
Post by: derty2 on 2012-04-22 09:51:16
I assume the task is this: Right-click context menu -> File Operations -> Rename to...
Would you like share the exact details of "it" in "unfortunately it doesn't work" so I can also get a handle on your problem ?
Title: Replacing slash in filename?
Post by: Tigermess on 2012-04-24 18:37:51
Of course. I have MP3 file with "test title 1 / test title 2" as TITLE tag.

I run Rename to... the way you wrote. I fill the File name pattern as can be seen in the screenshot.

(http://img254.imageshack.us/img254/3084/renamea.jpg) (http://imageshack.us/photo/my-images/254/renamea.jpg/)

In the preview, you can see that slash was replaced with dash instead of ampersand. After clicking run, file is renamed with dash instead of ampersand. The string and everything is correct - proof is in following screen:

(http://img692.imageshack.us/img692/1129/rename2d.jpg) (http://imageshack.us/photo/my-images/692/rename2d.jpg/)

See that I exchanged slash for "test title 2" - and this expression is replaced without any problem. Any other expression or character is replaced without problem, only slash is hard-replaced by dash and this can't be changed (backwards slash is possibly unchangeable too, I didn't test it yet).
Title: Replacing slash in filename?
Post by: yanni on 2012-04-24 19:43:38
Quote
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.

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 _.

As you can see, this behaviour is intended. Only workaround I can see right now, is to replace the hyphen-character (-) instead.
Title: Replacing slash in filename?
Post by: Dynamic on 2012-04-26 10:55:00
Other option is to create a new tag containing your new modified filename using the string handling you desire then read that tag into the rename dialogue instead of %title%

Perhaps easiest is to temporarily change %title% tags in the tag editing scripts to replace all '/' with some other character that doesn't occur legitimately in your playlists
(there's a lot in the Windows character set,
such as ALT+0182 (hold down alt, use the number pad to type 0182 then release, or use Windows Character Map in Programs/Accessories/System Tools) and this character is legal in Windows filenames, so fb2k's renamer should leave it alone.
which gives the Pilcrow symbol, ¶)
then do the rename, replacing ¶ with &
then re-edit the %title% tags, replacing all Pilcrows (¶) with forward slashes (/) in the %title% tags to revert to your original tags after the rename.

But for most people they won't be so worried about the detail so long as the tags show the desired info and the filename is intelligible enough to get the gist, a reason I support this automated behaviour in fb2k which makes life a lot easier.