The readdir procedure


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.



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);
      d : dir;
      fn : filename;

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


Operating Systems: All
Standard Pascal: No