Page 1 of 1

getpathcomponent parent and partial paths

Posted: 27 Sep 2016 07:40
by autocart
Hi all,

gpc("\Stücklistenpflege\test.txt", "parent"); //-> "Stücklistenpflege" - expected
gpc("Stücklistenpflege\test.txt", "parent"); //-> "Stücklistenpflege" - expected
gpc("\test.txt", "parent"); //-> "" - expected
gpc("test.txt", "parent"); //-> "test.txt" - ???

Is this a bug? I would think so...

Regards, S.

Re: getpathcomponent parent and partial paths

Posted: 27 Sep 2016 08:37
by admin
You would expect ""?

BTW, what would you expect here?
echo gpc("C:", "parent"); //-> ???
echo gpc("C:\", "parent"); //-> ???

Re: getpathcomponent parent and partial paths

Posted: 27 Sep 2016 11:56
by autocart
Hi Don,
thx for this good question.

in both cases I would expect
""
as a result.
(As I see, when trying it out with the current version, I do get "C:" in both cases, though.)

Re: getpathcomponent parent and partial paths

Posted: 27 Sep 2016 15:08
by admin
I think both ways could be argued for. But, when I change it now, I would break old code. So IMO it's best to leave it as it is.

Re: getpathcomponent parent and partial paths

Posted: 28 Sep 2016 12:39
by LittleBiG
So it means "no parent" can be checked only by gpc($path, "parent") == $path instead of gpc($path, "parent") == "". It is strange enough to be worth to mention in the help file in my opinion.
admin wrote:I think both ways could be argued for.
I would be very curious how can be argued for the current way of working, save for breaking old codes. :mrgreen:

Re: getpathcomponent parent and partial paths

Posted: 28 Sep 2016 13:05
by admin
My idea of parent was to return the next available upper path. If there is none then the item itself is the upmost path and is returned.

(Okay, I'm not convinced myself...) :whistle:

Re: getpathcomponent parent and partial paths

Posted: 28 Sep 2016 13:15
by Filehero
admin wrote:(Okay, I'm not convinced myself...) :whistle:
Yes, by common definition a node without a parent is the root node of any given tree-like structure, isn't it? Hence, I would expect "null" >(aka "") there as well.

Re: getpathcomponent parent and partial paths

Posted: 28 Sep 2016 15:00
by admin
Convinced. Actually I now see it as a bug that has to be fixed.