GetParentDirectory()
Posted: Thu Dec 22, 2016 1:05 pm
GetParentDirectory(ChildDirectory$)
A nice way to travel back up a path.
A nice way to travel back up a path.
http://www.purebasic.com
https://www.purebasic.fr/english/
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:'"