The readdir procedure

Description

The readdir procedure reads a filename from a directory variable (i.e. retrieves the name of the next file in the directory associated with the directory variable). NOTE: Directories are also called folders.

Parameters

Example

The simple program below opens the current directory and then uses "readdir" to read the names of all the files in the directory, and then finally closes the directory when done.

   program listdir(output);
   var
      d : dir;
      fn : filename;

   begin
      opendir(d, '.');   Open current directory 
      repeat
         readdir(d, fn);   Get next file in directory 
         if fn <> '' then
            writeln(fn);
      until fn = '';
      closedir(d)  Close directory 
   end.

Portability

Operating Systems: All
Standard Pascal: No