Example #1
0
 /**
  * List all the files and directories within the given directory.
  *
  * @param directory The directory.
  * @param recursive Whether the filter should recursively list subdirectories.
  * @param includeFiles Whether files should be included.
  * @param includeDirectories Whether directories should be included.
  * @param fileFilter The filter (with ? and * as wildcards) to filter the accepted file names.
  * @return The array of all the files and directories found.
  */
 public static File[] listFiles(
     File directory,
     boolean recursive,
     boolean includeFiles,
     boolean includeDirectories,
     String fileFilter) {
   RecursiveFileFilter filter =
       new RecursiveFileFilter(recursive, includeFiles, includeDirectories, fileFilter);
   directory.list(filter);
   List<File> files = filter.getFiles();
   Collections.sort(files, new FileComparator());
   return files.toArray(new File[files.size()]);
 }
Example #2
0
  /**
   * Process this event with the given arguments. The number of arguments provided must be equal to
   * the number of formal parameters defined for this event, and their types must match. The actions
   * of this event are executed.
   *
   * @param arguments The arguments used to process this event, which must be either an ArrayToken
   *     or a RecordToken.
   * @return A refiring data structure that contains a non-negative double number if refire() should
   *     be called after that amount of model time, or null if refire() need not be called.
   * @exception IllegalActionException If the number of the arguments or their types do not match,
   *     the actions cannot be executed, or any expression (such as guards and arguments to the next
   *     events) cannot be evaluated.
   * @see #refire(Token, RefiringData)
   */
  public RefiringData fire(Token arguments) throws IllegalActionException {
    File[] listedFiles =
        RecursiveFileFilter.listFiles(
            directory.asFile(),
            ((BooleanToken) recursive.getToken()).booleanValue(),
            ((BooleanToken) includeFiles.getToken()).booleanValue(),
            ((BooleanToken) includeDirectories.getToken()).booleanValue(),
            filter.stringValue());
    StringBuffer buffer = new StringBuffer("{ ");
    int i = 0;
    for (File file : listedFiles) {
      if (i++ > 0) {
        buffer.append(",\n  ");
      }
      buffer.append('\"');
      buffer.append(StringUtilities.escapeString(file.getPath()));
      buffer.append('\"');
    }
    if (listedFiles.length > 0) {
      buffer.append(' ');
    }
    buffer.append('}');
    files.setExpression(buffer.toString());

    return super.fire(arguments);
  }