Skip to content
Urs Liska edited this page Mar 24, 2015 · 3 revisions

OS independent Path Handling

openLilyLib provides a module that is similar to Python's os.pathmodule in that it provides commands to handle file paths that work on all supported operating systems, hiding the differences in path syntax from the user. After initializing openLilyLib these are available without further action and without any namespacing. The commands have been created for handling openLilyLib's own infrastructure but they can be useful for many other applications in user code as well.

Note:
All functions that take a path argument are quite liberal about their input argument (except as stated otherwise). They accepts Windows and Unix strings or lists with string? or symbol? elements. The types of the list elements may even be mixed. In all cases the input argument is turned into a list of string elements using the split-path function.
Paths can be relative or absolute, not affecting the way the functions work.

  • (absolute-path? path)
    Return #t if the given path is an absolute path, #f if it is relative.
  • (absolute-path path)
    Return the absolute, normalized path for the input argument. If path is a string, a (Unix-style) string is returned, if it is a list then a list of string elements.
    If path is an absolute path it is only normalized, but if it is a relative path this is interpreted relatively to the current working directory.
  • is-windows
    is #t when the currently run operating system is Windows, #f in other cases.
  • (get-cwd-list)
    Return the current working directory as a path list.
  • (join-dot-path path)
    Return a string representation of a path, joined with dots. Used (e.g.) for displaying option paths in openLilyLib.
  • (join-unix-path path)
    Return a Unix style path string from the given path. These strings can be used in many context when paths in LilyPond syntax are needed.
  • (location-extract-path location)
    Actually I don't really know what this does and is supposed to do in contrast to (normalize-location).
  • (normalize-location location)
    Return a normalized (Unix) string for the given location object. (locations are always absolute paths).
  • (normalize-path path)
    Normalize a path by resolving . and .. elements. If path is a string a normalized (Unix-style) string is returned, if it is a list then a list of string elements.
  • os-path-separator
    is "" on Windows, "/" otherwise.
    Can be used when you want to construct file paths for the currently run OS. Note that there are better functions to create absolute paths.
  • (split-path path)
    returns a list with path elements of type string. It is used internally because most path operations in the os-path module operate on path lists.
  • \thisFile
    Return the normalized, absolute (Unix) path to the file where this command has been called from (not the file that is compiled by LilyPond).
  • (this-file-compiled? parser location) or \thisFileCompiled
    Return #t if the file where this function is called is the one that is actually compiled by LilyPond.