GetParentDirectory()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
the.weavster
Addict
Addict
Posts: 1576
Joined: Thu Jul 03, 2003 6:53 pm
Location: England

GetParentDirectory()

Post by the.weavster »

GetParentDirectory(ChildDirectory$)

A nice way to travel back up a path.
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

Re: GetParentDirectory()

Post by Lunasole »

I often too have ideas of adding lot of such small useful stuff, but generally such small things are not needed at language level and only adding extra work for PB team.

You can use something like following

Code: Select all

; Path$         directory or file path
; RETURN:    parent path from a current path or empty string if reached top
Procedure$ ParentDir (Path$)
	ProcedureReturn GetPathPart(RTrim(GetPathPart(Path$), "\"))
EndProcedure

; test
Debug "'" + ParentDir(ProgramFilename()) + "' from '" + ProgramFilename() + "'"
Debug "'" + ParentDir("D:\1\") + "' from 'D:\1\'"
Debug "'" + ParentDir("D:\") + "' from 'D:\'"
Debug "'" + ParentDir("D:") + "' from 'D:'"
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
Post Reply