Module Dir Reference

This module includes procedures to read directory contents.

Constants

This section is empty.

Types

Rec = RECORD   eod: BOOLEAN;  

(* TRUE if end of directory is reached *)

  isDir: BOOLEAN;  

(* TRUE if current entry is a directory *)

  res: INTEGER;  

(* Result. 0 means no error. *)

  name: ARRAY 512 OF CHAR;  

(* File or directory name *)

  path: ARRAY 1024 OF CHAR  

(* Path that has been set *)

END
;

Directory rider record. Holds data of a single file or directory entry while reading contents of a directory.

Variables

This section is empty.

Procedures

PROCEDURE Close (VAR r: Rec);

Close a directory.

MUST BE CALLED to avoid leaking C directory streams.

!TODO add this to finalization.

PROCEDURE FileExists (name: ARRAY OF CHAR): BOOLEAN;

Returns TRUE if the file with the given name exists.

PROCEDURE First (VAR r: Rec; path: ARRAY OF CHAR);

Initiates reading the directory with the given path.

After the call to First the directory entry rider r holds data about the first entry of the directory at path. Check if r.res = 0 to make sure First was successful. Use Next with the same r and used check r.eod to see when it is time to stop reading the directory.

PROCEDURE GetCwd (VAR dir: ARRAY OF CHAR);

Returns a full path to the current working directory.

PROCEDURE IsDir (name: ARRAY OF CHAR): BOOLEAN;

Returns TRUE if the given file name refers to a directory.

PROCEDURE Next (VAR r: Rec);

Reads the next directory entry after the one refered by r.

First call First(r, path) with the same r and a path to a directory. Then use r.eod and Next(r) to iterate through the entries.

PROCEDURE Rewind (VAR r: Rec);

Starts reading directory contents from the beginning.