Author Topic: Failed with functions to get the dir structure to sync on portable device.  (Read 1447 times)

farrukh

  • Newbie
  • *
  • Posts: 17
Hi,

I am trying to create the same folder structure on my portable USB as it is on my computer drive. The Fields <Folder Name>\<filename> would only create 1 level of folder where the mp3 files are located, but not the subfolder structure. So I tried to use Function Fields e.g.
Code
$Replace($CutLeft(<path>,3),\,\\)\<filename>
.
- The function "$CutLeft(<path>,3)"  would give the folder structure by cutting out the "[Drive]:\" and giving the rest of the Path including subfolder. See the Preview:

But this would sync the folders without "\" e.g. the folders on my Portable USB Device would be created like:
I:\Audio Books 100 ways to motivate yourself\100 ways to motivate your... mp3
It is not rendering the "\" and converting to " ", while the "\\" before file name is rendered to "\".  So to cop this, I tried to replace "\" with "\\" using the following method:
Code
$Replace($CutLeft(<path>,3),\,\\)\<filename>
Although, in the Preview, it seems to be generating the folder structure fine, but when I sync, it again misses the "\" and convert to spaces.
It also never worked with $Replace($CutLeft(<path>,3),"\","\\")\<filename>.


1. Is this the correct way to use functions? But it is not working eventhough the preview was correct.
2. How to create the same folder and files structure on portable usb with sync, as it is on the source drive?

karbock

  • Sr. Member
  • ****
  • Posts: 565
Hello Farukh,

(1) The content of <path> always ends with a "\", so no need to add one in front of <filename> in your formula.

(2) The solution for your problem (backslashes replaced by spaces) is described here:
https://getmusicbee.com/forum/index.php?topic=41046.0

Mayibongwe

  • Sr. Member
  • ****
  • Posts: 1733
  • Heal The World
This should help; follow the link below and report back.

It sounds easy, but if it's what I think it is, then this is actually one of the hardest MusicBee puzzles I've personally had to solve thus far.
A link to an identical problem from the past: https://getmusicbee.com/forum/index.php?topic=37129.msg204206#msg204206
What makes this kind of puzzle particularly hard to solve is that what the template editor shows is not what goes on behind the scenes.

Edit: I was just about to reference the same link as karbock.
Strength and Honour (2025)

tjinc

  • Sr. Member
  • ****
  • Posts: 838
2. How to create the same folder and files structure on portable usb with sync, as it is on the source drive?
[/b][/size]
If you are using 'Device Synching' then I think you should be able to achieve this using the setting 'preserve folders and filenames':

farrukh

  • Newbie
  • *
  • Posts: 17
This should help; follow the link below and report back.

It sounds easy, but if it's what I think it is, then this is actually one of the hardest MusicBee puzzles I've personally had to solve thus far.
A link to an identical problem from the past: https://getmusicbee.com/forum/index.php?topic=37129.msg204206#msg204206
What makes this kind of puzzle particularly hard to solve is that what the template editor shows is not what goes on behind the scenes.

Edit: I was just about to reference the same link as karbock.

Hello Farukh,

(1) The content of <path> always ends with a "\", so no need to add one in front of <filename> in your formula.

(2) The solution for your problem (backslashes replaced by spaces) is described here:
https://getmusicbee.com/forum/index.php?topic=41046.0

Thanks, guys, for the tip.

However, I can't update in Filename Char Mapping dialog, \ with an = sign, even after giving the Admin Privileges to MusicBee. All the cells with predefined characters are read-only. But if I create a new entry with replace: and with: using \ and =, it let me enter it:
but displaying the following error:

So how to update the existing record with \ and replace it with =, while it won't let me do it?

BTW, i'm using MusicBee version 3.5.8681...
Last Edit: June 11, 2024, 04:25:06 AM by farrukh

farrukh

  • Newbie
  • *
  • Posts: 17
2. How to create the same folder and files structure on portable usb with sync, as it is on the source drive?
[/b][/size]
If you are using 'Device Synching' then I think you should be able to achieve this using the setting 'preserve folders and filenames':

This won't create the deep level of subdirectories, but only creates 1st level of folder and copies all the files in that folder... no subdirectories.

Zak

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2553
However, I can't update in Filename Char Mapping dialog, \ with an = sign, even after giving the Admin Privileges to MusicBee. All the cells with predefined characters are read-only.
They're not read-only - but they have spaces there by default and only allow one character, so you can't change it until you delete the existing space character first.

That's not related to your actual problem though. Those values are to avoid naming files with characters that are invalid on Windows, not as a general replacement for file paths created by other means.
Bee excellent to each other...

karbock

  • Sr. Member
  • ****
  • Posts: 565
If you are using 'Device Synching' then I think you should be able to achieve this using the setting 'preserve folders and filenames':
This won't create the deep level of subdirectories, but only creates 1st level of folder and copies all the files in that folder... no subdirectories.

Well, the folder tree structure is maintained here in the two tests I've just performed with a USB drive,
using option preserve folders and filenames:
  • one by specifying the parent folder to synchronise from (Preferences -> Devices -> Music -> (x) folders ... at the bottom)
  • one with Music -> (x) synchronise music -> (o) all music.
    I didn't let the 2nd test run until the end, but from the depth of the already copied directories, it was conclusive.

farrukh

  • Newbie
  • *
  • Posts: 17
Here is my config for usb:

And here is my songs list located on my local disk. Please observe the folder structure:

And after sync, here is the result:

It is supposed to be in I:\Music\Indian\Indian Misc\ and I:\Music\Indian\Old-Gold\, but it is copying into I:\Music\ folder because in the Device settings, we have mentioned Music\*. And just to confirm this, I set it to \* and guess what!!!, it copied to I:\Indian Misc\ and I:\Old-Gold\ folders.

Any clues to solve this?


If you are using 'Device Synching' then I think you should be able to achieve this using the setting 'preserve folders and filenames':
This won't create the deep level of subdirectories, but only creates 1st level of folder and copies all the files in that folder... no subdirectories.

Well, the folder tree structure is maintained here in the two tests I've just performed with a USB drive,
using option preserve folders and filenames:
  • one by specifying the parent folder to synchronise from (Preferences -> Devices -> Music -> (x) folders ... at the bottom)
  • one with Music -> (x) synchronise music -> (o) all music.
    I didn't let the 2nd test run until the end, but from the depth of the already copied directories, it was conclusive.

farrukh

  • Newbie
  • *
  • Posts: 17
However, I can't update in Filename Char Mapping dialog, \ with an = sign, even after giving the Admin Privileges to MusicBee. All the cells with predefined characters are read-only.
They're not read-only - but they have spaces there by default and only allow one character, so you can't change it until you delete the existing space character first.

That's not related to your actual problem though. Those values are to avoid naming files with characters that are invalid on Windows, not as a general replacement for file paths created by other means.

Thanks for the tip  :) . Yes, it was a space and with minor effort, I selected that space, deleted that and entered the = sign.
Now, I will try this with the Split and Replace functions in order to get the Target Paths with a working "\".

tjinc

  • Sr. Member
  • ****
  • Posts: 838
It is supposed to be in I:\Music\Indian\Indian Misc\ and I:\Music\Indian\Old-Gold\, but it is copying into I:\Music\ folder because in the Device settings, we have mentioned Music\*. And just to confirm this, I set it to \* and guess what!!!, it copied to I:\Indian Misc\ and I:\Old-Gold\ folders.

Any clues to solve this?

I agree with what you are seeing here - it seems that the folder structure is preserved only up to the first 'common folder'.
There has been a fair bit of 'discussion' on this function and Steven has admitted that it is far from perfect (it seems he would rather remove it altogether but is leaving it in as some people are using it happily).

Two options I can think of:
  1. If you are only ever synching tracks stored in your Indian subfolder, set the music files storage to Music\Indian\*
  2. If you are synching files from other subfolders as well, then do so at the same time and you should be ok as you are.

farrukh

  • Newbie
  • *
  • Posts: 17
Hello Farukh,

(1) The content of <path> always ends with a "\", so no need to add one in front of <filename> in your formula.

(2) The solution for your problem (backslashes replaced by spaces) is described here:
https://getmusicbee.com/forum/index.php?topic=41046.0

Finally, it worked...  8)  :D

After the success of entering = sign against \ in File Mapping Dialog, the following Function worked:
Code
$CutLeft($Replace(<Path>,=,\),3)<Filename>
Instead of $Split(), I used $CutLeft() to drop Drive:\ and get rest of the Path.

Thanks a bunch for the rescue  8)

farrukh

  • Newbie
  • *
  • Posts: 17
It is supposed to be in I:\Music\Indian\Indian Misc\ and I:\Music\Indian\Old-Gold\, but it is copying into I:\Music\ folder because in the Device settings, we have mentioned Music\*. And just to confirm this, I set it to \* and guess what!!!, it copied to I:\Indian Misc\ and I:\Old-Gold\ folders.

Any clues to solve this?

I agree with what you are seeing here - it seems that the folder structure is preserved only up to the first 'common folder'.
There has been a fair bit of 'discussion' on this function and Steven has admitted that it is far from perfect (it seems he would rather remove it altogether but is leaving it in as some people are using it happily).

Two options I can think of:
  1. If you are only ever synching tracks stored in your Indian subfolder, set the music files storage to Music\Indian\*
  2. If you are synching files from other subfolders as well, then do so at the same time and you should be ok as you are.

I was evaluating MediaMonkey5 and it has <Folder> tag which would create the same folder structure on the target device, without any more customizations. I think, Steven should simply add something like <Folder> ...