| 1 |
.\" -*- mode: troff; coding: utf-8 -*- |
| 2 |
.\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) |
| 3 |
.\" |
| 4 |
.\" Standard preamble: |
| 5 |
.\" ======================================================================== |
| 6 |
.de Sp \" Vertical space (when we can't use .PP) |
| 7 |
.if t .sp .5v |
| 8 |
.if n .sp |
| 9 |
.. |
| 10 |
.de Vb \" Begin verbatim text |
| 11 |
.ft CW |
| 12 |
.nf |
| 13 |
.ne \\$1 |
| 14 |
.. |
| 15 |
.de Ve \" End verbatim text |
| 16 |
.ft R |
| 17 |
.fi |
| 18 |
.. |
| 19 |
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. |
| 20 |
.ie n \{\ |
| 21 |
. ds C` "" |
| 22 |
. ds C' "" |
| 23 |
'br\} |
| 24 |
.el\{\ |
| 25 |
. ds C` |
| 26 |
. ds C' |
| 27 |
'br\} |
| 28 |
.\" |
| 29 |
.\" Escape single quotes in literal strings from groff's Unicode transform. |
| 30 |
.ie \n(.g .ds Aq \(aq |
| 31 |
.el .ds Aq ' |
| 32 |
.\" |
| 33 |
.\" If the F register is >0, we'll generate index entries on stderr for |
| 34 |
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index |
| 35 |
.\" entries marked with X<> in POD. Of course, you'll have to process the |
| 36 |
.\" output yourself in some meaningful fashion. |
| 37 |
.\" |
| 38 |
.\" Avoid warning from groff about undefined register 'F'. |
| 39 |
.de IX |
| 40 |
.. |
| 41 |
.nr rF 0 |
| 42 |
.if \n(.g .if rF .nr rF 1 |
| 43 |
.if (\n(rF:(\n(.g==0)) \{\ |
| 44 |
. if \nF \{\ |
| 45 |
. de IX |
| 46 |
. tm Index:\\$1\t\\n%\t"\\$2" |
| 47 |
.. |
| 48 |
. if !\nF==2 \{\ |
| 49 |
. nr % 0 |
| 50 |
. nr F 2 |
| 51 |
. \} |
| 52 |
. \} |
| 53 |
.\} |
| 54 |
.rr rF |
| 55 |
.\" ======================================================================== |
| 56 |
.\" |
| 57 |
.IX Title "IO::Dir 3perl" |
| 58 |
.TH IO::Dir 3perl 2025-11-16 "perl v5.40.1" "Perl Programmers Reference Guide" |
| 59 |
.\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 60 |
.\" way too many mistakes in technical documents. |
| 61 |
.if n .ad l |
| 62 |
.nh |
| 63 |
.SH NAME |
| 64 |
IO::Dir \- supply object methods for directory handles |
| 65 |
.SH SYNOPSIS |
| 66 |
.IX Header "SYNOPSIS" |
| 67 |
.Vb 8 |
| 68 |
\& use IO::Dir; |
| 69 |
\& my $d = IO::Dir\->new("."); |
| 70 |
\& if (defined $d) { |
| 71 |
\& while (defined($_ = $d\->read)) { something($_); } |
| 72 |
\& $d\->rewind; |
| 73 |
\& while (defined($_ = $d\->read)) { something_else($_); } |
| 74 |
\& undef $d; |
| 75 |
\& } |
| 76 |
\& |
| 77 |
\& tie my %dir, \*(AqIO::Dir\*(Aq, "."; |
| 78 |
\& foreach (keys %dir) { |
| 79 |
\& print $_, " " , $dir{$_}\->size,"\en"; |
| 80 |
\& } |
| 81 |
.Ve |
| 82 |
.SH DESCRIPTION |
| 83 |
.IX Header "DESCRIPTION" |
| 84 |
The \f(CW\*(C`IO::Dir\*(C'\fR package provides two interfaces to perl's directory reading |
| 85 |
routines. |
| 86 |
.PP |
| 87 |
The first interface is an object approach. \f(CW\*(C`IO::Dir\*(C'\fR provides an object |
| 88 |
constructor and methods, which are just wrappers around perl's built in |
| 89 |
directory reading routines. |
| 90 |
.IP "new ( [ DIRNAME ] )" 4 |
| 91 |
.IX Item "new ( [ DIRNAME ] )" |
| 92 |
\&\f(CW\*(C`new\*(C'\fR is the constructor for \f(CW\*(C`IO::Dir\*(C'\fR objects. It accepts one optional |
| 93 |
argument which, if given, \f(CW\*(C`new\*(C'\fR will pass to \f(CW\*(C`open\*(C'\fR |
| 94 |
.PP |
| 95 |
The following methods are wrappers for the directory related functions built |
| 96 |
into perl (the trailing 'dir' has been removed from the names). See perlfunc |
| 97 |
for details of these functions. |
| 98 |
.IP "open ( DIRNAME )" 4 |
| 99 |
.IX Item "open ( DIRNAME )" |
| 100 |
.PD 0 |
| 101 |
.IP "read ()" 4 |
| 102 |
.IX Item "read ()" |
| 103 |
.IP "seek ( POS )" 4 |
| 104 |
.IX Item "seek ( POS )" |
| 105 |
.IP "tell ()" 4 |
| 106 |
.IX Item "tell ()" |
| 107 |
.IP "rewind ()" 4 |
| 108 |
.IX Item "rewind ()" |
| 109 |
.IP "close ()" 4 |
| 110 |
.IX Item "close ()" |
| 111 |
.PD |
| 112 |
.PP |
| 113 |
\&\f(CW\*(C`IO::Dir\*(C'\fR also provides an interface to reading directories via a tied |
| 114 |
hash. The tied hash extends the interface beyond just the directory |
| 115 |
reading routines by the use of \f(CW\*(C`lstat\*(C'\fR, from the \f(CW\*(C`File::stat\*(C'\fR package, |
| 116 |
\&\f(CW\*(C`unlink\*(C'\fR, \f(CW\*(C`rmdir\*(C'\fR and \f(CW\*(C`utime\*(C'\fR. |
| 117 |
.ie n .IP "tie %hash, 'IO::Dir', DIRNAME [, OPTIONS ]" 4 |
| 118 |
.el .IP "tie \f(CW%hash\fR, 'IO::Dir', DIRNAME [, OPTIONS ]" 4 |
| 119 |
.IX Item "tie %hash, 'IO::Dir', DIRNAME [, OPTIONS ]" |
| 120 |
.PP |
| 121 |
The keys of the hash will be the names of the entries in the directory. |
| 122 |
Reading a value from the hash will be the result of calling |
| 123 |
\&\f(CW\*(C`File::stat::lstat\*(C'\fR. Deleting an element from the hash will |
| 124 |
delete the corresponding file or subdirectory, |
| 125 |
provided that \f(CW\*(C`DIR_UNLINK\*(C'\fR is included in the \f(CW\*(C`OPTIONS\*(C'\fR. |
| 126 |
.PP |
| 127 |
Assigning to an entry in the hash will cause the time stamps of the file |
| 128 |
to be modified. If the file does not exist then it will be created. Assigning |
| 129 |
a single integer to a hash element will cause both the access and |
| 130 |
modification times to be changed to that value. Alternatively a reference to |
| 131 |
an array of two values can be passed. The first array element will be used to |
| 132 |
set the access time and the second element will be used to set the modification |
| 133 |
time. |
| 134 |
.SH "SEE ALSO" |
| 135 |
.IX Header "SEE ALSO" |
| 136 |
File::stat |
| 137 |
.SH AUTHOR |
| 138 |
.IX Header "AUTHOR" |
| 139 |
Graham Barr. Currently maintained by the Perl Porters. Please report all |
| 140 |
bugs at <https://github.com/Perl/perl5/issues>. |
| 141 |
.SH COPYRIGHT |
| 142 |
.IX Header "COPYRIGHT" |
| 143 |
Copyright (c) 1997\-2003 Graham Barr <[email protected]>. All rights reserved. |
| 144 |
This program is free software; you can redistribute it and/or |
| 145 |
modify it under the same terms as Perl itself. |