Class DirectoryList

java.lang.Object
ortus.boxlang.runtime.bifs.BIF
ortus.boxlang.runtime.bifs.global.io.DirectoryList

@BoxBIF public class DirectoryList extends BIF
  • Constructor Details

    • DirectoryList

      public DirectoryList()
      Constructor
  • Method Details

    • _invoke

      public Object _invoke(IBoxContext context, ArgumentsScope arguments)
      List the contents of a directory. Returns either an array, or a query depending on the listInfo argument.

      The listInfo argument can be one of the following:

      • name - Returns an array of the names of the items in the directory.
      • path - Returns an array of the absolute paths of the items in the directory.
      • query - Returns a query of the items in the directory containing the following fields:
        • attributes - The attributes of the item (R, W, X, H).
        • dateLastModified - The date the item was last modified.
        • directory - The directory containing the item.
        • mode - The mode of the item.
        • name - The name of the item.
        • size - The size of the item in bytes.
        • type - The type of the item (either "Dir" or "File").

      The filter argument can be the following:

      • A closure/lambda that takes a single argument (the path of the item) and returns a boolean. True to return it, false otherwise.
         DirectoryList( path: "/path/to/dir", filter: path -> path.endsWith(".txt") )
         
      • A string that is a glob pattern: E.g. "*.txt" to only return files with the .txt extension. Or you can use the | pipe to separate multiple patterns: E.g. "*.txt|*.csv" to return files with either the .txt or .csv extension.
      Specified by:
      _invoke in class BIF
      Parameters:
      context - The context in which the BIF is being invoked.
      arguments - Argument scope for the BIF.
      Returns:
      The result of the invocation
    • listingToPaths

      public Array listingToPaths(Stream<Path> listing)
    • listingToNames

      public Array listingToNames(Stream<Path> listing)
    • listingToQuery

      public Query listingToQuery(Stream<Path> listing, String sort)
    • listingToQueryNames

      public Query listingToQueryNames(Stream<Path> listing, Path basePath)