opendir() - Open Directory to Read File Names

This section describes Perl built-in functions, opendir() and readdir(), to open a file directory and read its file names and sub-directories.

There are 3 functions in Perl that help you to open a directory and read its file names:

1. opendir() - A function to open the specified directory and associate it to a directory handle with the following syntax:

rc = opendir(dir_handle, expression);

where "expression" specifies the path name of the directory to be opened, and "dir_handle" is the variable name of the new directory handle. opendir() returns true, if operation is successful.

Directory handle has its own name space. Same name can co-exist in different name spaces.

2. readdir() - A function to access the content of the specified directory handle. If the function is called in a scalar context, it will return the next entry. If the function is called in an array context, it will return the rest of entries. Examples of calling readdir() in scalar and array contexts:

$s = readdir(dir_handle);
@a = readdir(dir_handle);

3. closedir() - A function to close the directory associated with the specified directory handle.


Table of Contents

 About This Book

 Perl on Linux Systems

 ActivePerl on Windows Systems

 Data Types: Values and Variables

 Expressions, Operations and Simple Statements

 User Defined Subroutines

 Perl Built-in Debugger

 Name Spaces and Perl Module Files

 Symbolic (or Soft) References

 Hard References - Addresses of Memory Objects

 Objects (or References) and Classes (or Packages)

 Typeglob and Importing Identifiers from Other Packages

 String Built-in Functions and Performance

 File Handles and Data Input/Output

 Open Files in Binary Mode

Open Directories and Read File Names

opendir() - Open Directory to Read File Names - Sample Program to Read Directories - Displaying the Directory Tree - Searching Text in Directory Files

 File System Functions and Operations

 Image and Picture Processing

 Using DBM Database Files

 Using MySQL Database Server

 Socket Communication Over the Internet

 XML::Simple Module - XML Parser and Generator

 XML Communication Model

 SOAP::Lite - SOAP Server-Client Communication Module

 Perl Programs as IIS Server CGI Scripts

 CGI (Common Gateway Interface)

 XML-RPC - Remote Procedure Call with XML and HTTP

 RPC::XML - Perl Implementation of XML-RPC

 Integrating Perl with Apache Web Server Module for Building Web Pages

 LWP::UserAgent and Web Site Testing

 Converting Perl Script to Executable Binary

 Managing Perl Engine and Modules on macOS

 Archived Tutorials


 Full Version in PDF/EPUB