Perl readdir Function

Advertisements


Description

This function returns the next directory entry from the directory associated with DIRHANDLE in a scalar context. In a list context, returns all of the remaining directory entries in DIRHANDLE.

Syntax

Following is the simple syntax for this function:

readdir DIRHANDLE

Return Value

This function returns the next directory entry from the directory associated with DIRHANDLE in a scalar context. In a list context, returns all of the remaining directory entries in DIRHANDLE.

Example

Following is the example code showing its basic usage:

#!/usr/bin/perl -w

$dirname = "/tmp";

opendir ( DIR, $dirname ) || die "Error in opening dir $dirname\n";
while( ($filename = readdir(DIR))){
     print("$filename\n");
}
closedir(DIR);

When above code is executed, it produced following result

.
..
testdir


Advertisements
Advertisements