Code: Select all
SplitPathObj(Path, &Name?, &Dir?, &Ext?, &NameNoExt?, &Drive?) {
SplitPath(Path, &Name, &Dir, &Ext, &NameNoExt, &Drive)
return {Name: Name, Dir: Dir, Ext: Ext, NameNoExt: NameNoExt, Drive: Drive}
}
Path := "C:\folder\file.txt"
;suggested behaviour
MsgBox SplitPathObj(Path).Drive ;C:\
MsgBox SplitPathObj(Path, &MyVar).Dir "|" MyVar ;C:\folder|file.txt
if SplitPathObj(Path).Ext = "txt"
MsgBox "textfile"
;current alternative
MsgBox SplitPath(Path,,,,, &Drive) Drive ;C:
MsgBox SplitPath(Path, &MyVar, &Dir) Dir "|" MyVar ;C:\folder|file.txt
if SplitPath(Path,,, &Ext) Ext = "txt"
MsgBox "textfile"
I prefer the always return object variant but both have benefits.SplitPath could return an object when no output parameters are passed. Property names are probably easier to remember than parameter order, and easier to read and write than counting commas. This should have no negative impact on compatibility if added later, presuming scripts do not rely on SplitPath returning "".
Always returning an object (my idea) lets us do SplitPathObj(Path, &MyVar).Dir "|" MyVar
Returning an object only if no output parameters (Lexikos) does not break existing code like MsgBox SplitPath(Path,,,,, &Drive) Drive