admin wrote:Yep, good thinking, I'll add it.

Thanks.
And a another plus:
getpathcomponent() works for both "\" and "/"
whereas with gettoken() i would have to take care myself that it works for both cases.
admin wrote:I'd rather call it "component" than "folder" because also drives and files can be returned.
I didn't said anything against it
See, "folder" is ONE of the "component".
Analog to "path", "drive", "parent", "file", "base" and "ext"
- - -
BTW, getpathcomponent(path, drive);
will return the drive letter including the colon.
I think we want to get the drive letter without the colon.
It is easier to add an ':' ourself then to use an another .replace() command.
- - -
admin wrote:Question: what should be returned when level resp. index = 0?
Hmm, brain storming...
Since this is for users and not for programmers...
and since i meant that for "
folders" / hierarchy levels ...
and since there is already "drive"...
i have no real use for '0'
But i think '0' could still return the drive letter, since i have no better use for it.
And '1' should return the top folder. It's not the first level. But the first folder.
'2' the second top-level folder.
And '-1' returns the parent folder.
'-2' the grand parent folder name.
...
- - -
And how to handle the filename if present in path?
$A = "C:\Documents and Settings\Administrador\Meus documentos\XYplorer\Contas a receber.docx.bak";
Normally '-1' for an ARRAY would return blindly the filename "Contas a receber.docx.bak"
But now, since i talk about an "component" named 'FOLDER', should not '-1' return "XYplorer" ?
Hmm, hard. But i would tend to Yes, return folder names only.
$A = "C:\Documents and Settings\Administrador\Meus documentos\XYplorer\Contas a receber.docx.bak";
getpathcomponent([path] [, component] [, level] )
getpathcomponent( $A, "folder" , 0 ) // C
getpathcomponent( $A, "folder" , 1 ) // Documents and Settings
getpathcomponent( $A, "folder" , 2 ) // Administrador
getpathcomponent( $A, "folder" , 3 ) // Meus documentos
getpathcomponent( $A, "folder" , 14 ) // ' '
getpathcomponent( $A, "folder" , -2 ) // Meus documentos
getpathcomponent( $A, "folder" , -1 ) // XYplorer
getpathcomponent( $A, "drive" ) // C
getpathcomponent( $A, "path" ) // "C:\Documents and Settings\Administrador\Meus documentos\XYplorer
getpathcomponent( $A, "parent" ) // XYplorer
getpathcomponent( $A, "file" ) // Contas a receber.docx.bak
getpathcomponent( $A, "base" ) // Contas a receber.docx
getpathcomponent( $A, "ext" ) // bak
- - -
BTW, just tested: on an path without an file name
"C:\Documents and Settings\Administrador\Meus documentos\XYplorer\
getpathcomponent(path, path); will still drop blindly the last level, so here the parent folder.
getpathcomponent(path, parent); We will get here the grand parent name instead.
The same for 'file' and 'base' which returns both blindly the parent folder name.
And 'ext' will be empty (if not the folder has an dot by change)
I know it's by design, i just mention it here for reference.
Or you may want to check if the
last item has the folder attribute or not?
And then return more the expected result.
- - -
Just my cogitations. HTH? And sorry for much text.
More opinions?
.