NAME IO::Dirent - Access to dirent structs returned by readdir SYNOPSIS 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 IO::Dirent exports the following symbols by default: readdirent nextdirent readdirent 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! nextdirent is an enumerator for a directory handle. 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"; } Or by nextdirent in the same way: while( my $entry = nextdirent(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 This was written on FreeBSD and OS X which implement 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. BUILDING On OS X and recent Apple hardware, the undocumented ARCHFLAGS environment variable was valuable; without it, Perl would attempt to build i386 and ppc versions (which didn't work on my hardware): ARCHFLAGS="-arch x86_64" perl Makefile.PL I'd be happy to know if anyone knows of a way to detect this and set it during Makefile.PL. TO DO * For platforms that do not implement a dirent struct with file type, do a stat on the entry and populate the structure anyway. * Do some memory profiling (I'm not sure if I have any leaks or not). COPYRIGHT Copyright 2002, 2011 Scott Wiersdorf. This library is free software; you can redistribute it and/or modify it under the terms of the Perl Artistic License. AUTHOR Scott Wiersdorf, ACKNOWLEDGEMENTS Thanks to Nick Ing-Simmons for his help on the perl-xs mailing list. SEE ALSO dirent(5), the perlxstut manpage, the perlxs manpage, the perlguts manpage, the perlapi manpage