getpathcomponent parent and partial paths

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
autocart
Posts: 1391
Joined: 26 Sep 2013 15:22

getpathcomponent parent and partial paths

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

admin
Site Admin
Posts: 66679
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: getpathcomponent parent and partial paths

Post by admin »

You would expect ""?

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

autocart
Posts: 1391
Joined: 26 Sep 2013 15:22

Re: getpathcomponent parent and partial paths

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

admin
Site Admin
Posts: 66679
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: getpathcomponent parent and partial paths

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

LittleBiG
Posts: 1848
Joined: 08 Apr 2011 12:57
Location: Win10x64

Re: getpathcomponent parent and partial paths

Post 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:

admin
Site Admin
Posts: 66679
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: getpathcomponent parent and partial paths

Post 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:

Filehero
Posts: 2734
Joined: 27 Feb 2012 18:50
Location: Windows 11@100%

Re: getpathcomponent parent and partial paths

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

admin
Site Admin
Posts: 66679
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: getpathcomponent parent and partial paths

Post by admin »

Convinced. Actually I now see it as a bug that has to be fixed.

Post Reply