PROCEDURE rap$remove_elements_from_path (
  path, p: file = $required
  number_of_elements, noe: integer = $required  "to remove from path"
  new_path, np: (VAR) file = $required
  status)

  VAR
    command_file: file = $local//$name($unique)
    ignore_status: status
    last_element: string
    local_status: status
    loop: integer
    path_string: string
    pos: integer

  VAREND

COLLECT_TEXT command_file until='**'
  path_string = $string(path)
  FOR loop = 1 to number_of_elements DO
    last_element = $path($fname(path_string), last)
    pos = $scan_string(last_element, path_string)
    path_string = $substr(path_string, 1, pos-2)
  FOREND
**

  $system.include_file f=command_file status=local_status
  $system.delete_file f=command_file status=ignore_status
  EXIT procedure WITH local_status WHEN NOT local_status.normal

  new_path = $fname(path_string)

PROCEND rap$remove_elements_from_path
