IO::Dirent - Access to dirent structs returned by readdir


IO-Dirent documentation Contained in the IO-Dirent distribution.

Index


Code Index:

NAME

Top

IO::Dirent - Access to dirent structs returned by readdir

SYNOPSIS

Top

  use IO::Dirent;

  opendir DIR, "/usr/local/foo";
  my @entries = readdirent(DIR);
  closedir DIR;

  print $entries[0]->{name}, "\n";
  print $entries[0]->{type}, "\n";
  print $entries[0]->{inode}, "\n";

DESCRIPTION

Top

Returns a list of hashrefs. Each hashref contains the name of the directory entry, its inode for the filesystem it resides on and its type (if available). If the file type or inode are not available, it won't be there!

IO::Dirent exports the following symbols by default:

    readdirent

The following tags may be exported to your namespace:

    ALL

which includes readdirent and the following symbols:

    DT_UNKNOWN
    DT_FIFO
    DT_CHR
    DT_DIR
    DT_BLK
    DT_REG
    DT_LNK
    DT_SOCK
    DT_WHT

These symbols can be used to test the file type returned by readdirent in the following manner:

    for my $entry ( readdirent(DIR) ) {
        next unless $entry->{'type'} == DT_LNK;

        print $entry->{'name'} . " is a symbolic link.\n";
    }

For platforms that do not implement file type in its dirent struct, readdirent will return a hashref with a single key/value of 'name' and the filename (effectively the same as readdir). This is subject to change, if I can implement some of the to do items below.

CAVEATS

Top

This was written on FreeBSD which implements a robust (but somewhat non-standard) dirent struct and which includes a file type entry. I have plans to make this module more portable and useful by doing a stat on each directory entry to find the file type and inode number when the dirent.h does not implement it otherwise.

Improvements and additional ports are welcome.

TO DO

Top

COPYRIGHT

Top

AUTHOR

Top

Scott Wiersdorf, <scott@perlcode.org>

ACKNOWLEDGEMENTS

Top

Thanks to Nick Ing-Simmons for his help on the perl-xs mailing list.

SEE ALSO

Top

dirent(5), perlxstut, perlxs, perlguts, perlapi

COPYRIGHT AND LICENSE

Top


IO-Dirent documentation Contained in the IO-Dirent distribution.

package IO::Dirent;

use strict;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);

require Exporter;
require DynaLoader;

@ISA = qw(Exporter DynaLoader);
@EXPORT_OK = qw( DT_UNKNOWN
		 DT_FIFO
		 DT_CHR
		 DT_DIR
		 DT_BLK
		 DT_REG
		 DT_LNK
		 DT_SOCK
		 DT_WHT
	       );
@EXPORT = qw( readdirent );
%EXPORT_TAGS = ('ALL' => [@EXPORT, @EXPORT_OK]);
$VERSION = '0.04';

use constant DT_UNKNOWN =>   0;
use constant DT_FIFO    =>   1;    ## named pipe (fifo)
use constant DT_CHR     =>   2;    ## character special
use constant DT_DIR     =>   4;    ## directory
use constant DT_BLK     =>   6;    ## block special
use constant DT_REG     =>   8;    ## regular
use constant DT_LNK     =>  10;    ## symbolic link
use constant DT_SOCK    =>  12;    ## socket
use constant DT_WHT     =>  14;    ## whiteout

bootstrap IO::Dirent $VERSION;

1;
__END__