Skip to main content

Topic: Replacing slash in filename? (Read 2867 times) previous topic - next topic

0 Members and 1 Guest are viewing this topic.
  • Tigermess
  • [*][*]
Replacing slash in filename?
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? :-(

  • derty2
  • [*][*][*][*][*]
Replacing slash in filename?
Reply #1
$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.

  • Tigermess
  • [*][*]
Replacing slash in filename?
Reply #2
Hi, thanks, I tried the strings you sent, unfortunately it doesn't work :-( Does it work for you in File Operations?

  • derty2
  • [*][*][*][*][*]
Replacing slash in filename?
Reply #3
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 ?

  • Tigermess
  • [*][*]
Replacing slash in filename?
Reply #4
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.



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:



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

  • yanni
  • [*][*]
Replacing slash in filename?
Reply #5
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.

  • Dynamic
  • [*][*][*][*][*]
Replacing slash in filename?
Reply #6
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.
Dynamic – the artist formerly known as DickD