Class DirectoryListing

  • All Implemented Interfaces:
    java.io.FilenameFilter, java.lang.Cloneable, Actor, Executable, FiringsRecordable, Initializable, SequenceActor, TypedActor, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

    public class DirectoryListing
    extends SequenceSource
    implements java.io.FilenameFilter
    Given a URL or directory name, produce an array of file names in that directory that match an (optional) pattern.

    The file names include the complete path, unless relative is set to true, in which case, the names are relative to the directory. The pattern is a regular expression. For a reference on regular expression syntax see: http://download.oracle.com/javase/tutorial/essential/regex/

    If directoryOrURL is a local directory (not a URL), then you can optionally list only contained files or directories. If listOnlyDirectories is true, then only directories will be listed on the output. If listOnlyFiles is true, then only files will be listed on the output. If both are true, then an exception is thrown.

    If directoryOrURL is a URL, then this actor assumes that the server will list the contents of the referenced directory in an HTML file where each file listed will have the following form:

     <a href="filename">filename</a>
     

    If the filename is longer than 20 characters, then only the first 20 characters of the two appearances of the filename are compared, since some servers truncate the file names.

    If allowEmptyDirectory controls whether reading an empty directory will throw an exception.

    Note that DirectoryListing returns the contents of the directory in a different order depending on whether one is using the Sun JVM or the IBM JVM. Thus, you may want to connect the output to an ArraySort actor.

    Since:
    Ptolemy II 4.0
    Version:
    $Id$
    Author:
    Christopher Hylands, Edward A. Lee, Contributor: Jianwu Wang
    Pt.AcceptedRating:
    Red (liuj)
    Pt.ProposedRating:
    Yellow (eal)
    • Field Detail

      • directoryOrURL

        public FilePortParameter directoryOrURL
        The directory name or URL from which to read. This is a string with any form accepted by FilePortParameter. By default, this is empty. An empty string is equivalent to specifying "$CWD", the current working directory.
      • listOnlyDirectories

        public Parameter listOnlyDirectories
        If true, and directoryOrURL refers to a local directory (not a URL), then only directories will be listed on the output. If directoryOrURL is a URL, then this parameter is ignored (there appears to be no reliable way to tell whether the URL refers to a directory or file). This is a boolean that defaults to false.
      • listOnlyFiles

        public Parameter listOnlyFiles
        If true, and directoryOrURL refers to a local directory (not a URL), then only files will be listed on the output. If directoryOrURL is a URL, then this parameter is ignored (there appears to be no reliable way to tell whether the URL refers to a directory or file). This is a boolean that defaults to false.
      • allowEmptyDirectory

        public Parameter allowEmptyDirectory
        If true, and directoryOrURL refers to a local directory (not a URL), that is empty, then the output will be empty string array and no exception is reported. If directoryOrURL is a URL, then this parameter is ignored (there appears to be no reliable way to tell whether the URL refers to a directory or file). This is a boolean that defaults to false.
      • pattern

        public StringParameter pattern
        If non-empty, then only output file and directory names that match the specified (regular expression) pattern. The default value of this parameter is the empty String "", which indicates that everything matches.
      • recursive

        public Parameter recursive
        Whether files in the subdirectories should be searched as well. The recursive parameter only works if directoryOrURL refers to a local directory (not a URL). This is a boolean that defaults to false.
      • relative

        public Parameter relative
        If true, then produce an array with file names relative to the specified directory. This is a boolean that defaults to false, which causes the absolute (complete) path to be produced.
    • Method Detail

      • accept

        public boolean accept​(java.io.File directory,
                              java.lang.String name)
        Return true if the specified name matches the specified pattern, or if no pattern has been specified.
        Specified by:
        accept in interface java.io.FilenameFilter
        Parameters:
        directory - The directory in which the file was found (ignored, but required by the FilenameFilter interface).
        name - The name of the file or directory.
        Returns:
        True if the specified name matches.