Полезная информация

Learning Perl on Win32 Systems

Learning Perl on Win32 SystemsSearch this book
Previous: 12.3 Directory HandlesChapter 12
Directory Access
Next: 12.5 Reading a Directory Handle
 

12.4 Opening and Closing a Directory Handle

The opendir function is used to open a directory handle for reading. You give it the name of a new directory handle and a string value denoting the name of the directory to be opened. The return value from opendir is true if the directory can be opened, false otherwise. Here's an example:

opendir(NT,"c:/winnt") || die "Cannot opendir c:/winnt: $!";

Normally, at this point, we'd go playing with the directory handle NT, but it's probably nice to know how to close the directory handle first. This is done with closedir, in a similar manner to using close, like so:

closedir(NT);

Like close, closedir is often unnecessary, as all directory handles are automatically closed before they're reopened or at the end of the program.


Previous: 12.3 Directory HandlesLearning Perl on Win32 SystemsNext: 12.5 Reading a Directory Handle
12.3 Directory HandlesBook Index12.5 Reading a Directory Handle