IO::Dir#

Native implementation of IO::Dir

Provides object-oriented directory operations compatible with Perl’s IO::Dir. IO::Dir objects are blessed hashrefs. The __dh_id key stores the directory handle ID (u64) that maps to an entry in DIRHANDLE_TABLE.

Functions#

new#

Constructor. With no arguments, returns an unopened IO::Dir object. With a directory name, opens the directory and returns a blessed handle.

use IO::Dir;
my $d = IO::Dir->new("/tmp");
my $d = IO::Dir->new();

open#

Opens (or re-opens) a directory on an existing IO::Dir object. Closes any previously opened directory first. Returns 1 on success, undef on failure.

my $d = IO::Dir->new;
$d->open("/tmp") or die $!;

read#

Reads the next directory entry. Returns the entry name as a string, or undef at end-of-directory.

while (defined(my $entry = $d->read)) {
    print "$entry\n";
}

close#

Closes the directory handle and removes it from DIRHANDLE_TABLE.

$d->close();

rewind#

Resets the directory read position to the beginning.

$d->rewind();

seek#

Sets the directory read position to a given offset (as returned by tell).

$d->seek($saved_pos);

tell#

Returns the current directory read position, or -1 on error.

my $pos = $d->tell();

DESTROY#

Destructor. Automatically closes the directory handle when the object goes out of scope.