Page 1 of 1

GetParentDirectory()

Posted: Thu Dec 22, 2016 1:05 pm
by the.weavster
GetParentDirectory(ChildDirectory$)

A nice way to travel back up a path.

Re: GetParentDirectory()

Posted: Thu Dec 22, 2016 3:56 pm
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:'"