Example 2: Browsing directories

This program takes a directory path as an argument and scans the content recursively:
IMPORT os

MAIN
  CALL showDir(arg_val(1))
END MAIN

FUNCTION showDir(path)
  DEFINE path STRING
  DEFINE child STRING
  DEFINE h INTEGER

  IF NOT os.Path.exists(path) THEN
     RETURN
  END IF

  IF NOT os.Path.isdirectory(path) THEN
     DISPLAY " ", os.Path.basename(path)
     RETURN
  END IF

  DISPLAY "[", path, "]"
  CALL os.Path.dirsort("name", 1)
  LET h = os.Path.diropen(path)
  WHILE h > 0
     LET child = os.Path.dirnext(h)
     IF child IS NULL THEN EXIT WHILE END IF
     IF child == "." OR child == ".." THEN CONTINUE WHILE END IF
     CALL showDir( os.Path.join( path, child ) )
  END WHILE

  CALL os.Path.dirclose(h)

END FUNCTION