@fered: /* in this case does not mean zero or more slashes, but rather a slash followed by any number of characters. That means if your path starts with a slash, the result will be the empty string!
–
l0b0Oct 25 '11 at 9:13

I had considered, as per the example, that there would only be trailing slashes. However, to adapt to the possibility of a leading slash(es), bash's extglob (with regex) can by used.. shopt -s extglob; ${parts[@]%%/+(/)} ...
–
Peter.OOct 26 '11 at 2:54

The simple answer is to stop worrying and love multiple slashes. Multiple slashes have the same effect as a single slash (except that a path beginning with // has a different meaning on a few systems; unix emulation layers on Windows are the only ones I can name). That's by design, and being able to assemble file names without having to worry about multiple slashes was a major part of that design decision.

You can squish the duplicate slashes while you're at it, but that's purely cosmetic.

setopt extended_glob
dir=${${(j:/:)FOLDERS}//\/\/##/\/}

In ksh and bash, you can join an array using the first character of $IFS as a separator. You can then squish the duplicate slashes. In bash, you'll need to do shopt -s extglob to enable the ksh globs in the last line of the snippet below.

bash 4 introduced extended globbing, which enables regular expression matching in parameter substitution ${var....} ... It is turned off by default. To enable it for your script, simply set the shell option extglob...