| Prev | Perl Notes |
Next |
Imagine saving each message in a guestbook to an individual file within the Messages directory. It would be very usefull to be able to look at the directory's contents from within the script to see the files it contains. The opendir function lets you do just that.
To access a directory:
opendir(LOGDIR, ".") || @ErrorMessage;
@files = readdir (LOGDIR);
closedir(LOGDIR);
if (@files) {
print "You can choose from the following logs:";
foreach $filename (@files) {
print $filename unless ($filename =~ /^\.+$/);
}
}
|
Don't forget to close the directory after your done.
| Prev | Home | Next |