Learning Perl on Win32 Systems

Learning Perl on Win32 SystemsSearch this book
Previous: 12.2 GlobbingChapter 12
Directory Access
Next: 12.4 Opening and Closing a Directory Handle
 

12.3 Directory Handles

UNIX and POSIX programmers are used to reading directories and their contents using a system library function called readdir. As it turns out, this function is what Perl uses to provide directory access. Perl implements readdir (and its companions) using a new type of object called directory handles. A directory handle is a name from yet another namespace, and the cautions and recommendations that apply to filehandles also apply to directory handles (you can't use a reserved word, and uppercase is recommended). The filehandle FRED and the directory handle FRED are unrelated.

The directory handle represents a connection to a particular directory. Rather than reading data (as from a filehandle), you use the directory handle to read a list of filenames within the directory. Directory handles are always opened read only; you cannot use a directory handle to change the name of a file or to delete a file.


Previous: 12.2 GlobbingLearning Perl on Win32 SystemsNext: 12.4 Opening and Closing a Directory Handle
12.2 GlobbingBook Index12.4 Opening and Closing a Directory Handle