Oberon || Library || Module Index || Search Engine || Definition || Module


Ulm's Oberon Library:
ScanDir


NAME

ScanDir - pattern directed directory scan

SYNOPSIS

PROCEDURE Match(filename, pattern: ARRAY OF CHAR) : BOOLEAN;
PROCEDURE Open(VAR s: Streams.Stream; pattern: ARRAY OF CHAR);

DESCRIPTION

ScanDir implements the patterns of sh(1) and allows a sh(1)-compatible file pattern evaluation. Patterns are defined as follows:
?        matches any character
*        matches any (possibly empty) sequence
[...]    matches any character inside []
[!...]   matches any character but those inside []
[a-z]    matches letters 'a' to 'z'
\x       matches x
x        matches x
Note that "*" does not match directory slashes ("/") and "." at the beginning of a path component.

Match returns TRUE if filename matches pattern.

Open returns a stream with the list of filenames matched by pattern. The filenames are in alphabetically order and 0X-terminated. Initially, 0X is the line terminator in the sense of StreamDisciplines. Directories without read and execute permission are not examined.

EXAMPLE

Following example prints the filenames of all Oberon source files in the current directory:
PROCEDURE ListSources;
   VAR
      s: Streams.Stream;
      ch: CHAR;
BEGIN
   ScanDir.Open(s, "*.o[dm]");
   WHILE Streams.ReadByte(s, ch) DO
      IF ch = 0X THEN
         Write.Ln;
      ELSE
         Write.Char(ch);
      END;
   END;
   Streams.Release(s);
END ListSources;

DIAGNOSTICS

Errors during the access of the stream are converted into events of RelatedEvents. By default, these events are being queued. Errors which result from failures of examining directories do not lead to read errors, so ScanDir skips unreadable directories instead. Thus, the only way to check for failures is to examine the event queue.

SEE ALSO

sh(1)                     Bourne shell: shell patterns
RelatedEvents          handling of error events
StreamDisciplines      definition of line terminator
Streams                stream operations
Texts                  in-memory streams

BUGS

There are no patterns which allow a recursive traverse (compare to "[...]" of VMS).
Edited by: borchert, last change: 2003/07/10, revision: 1.6, converted to HTML: 2003/07/10

Oberon || Library || Module Index || Search Engine || Definition || Module