1File::Listing(3)      User Contributed Perl Documentation     File::Listing(3)
2
3
4

NAME

6       File::Listing - Parse directory listing
7

VERSION

9       version 6.16
10

SYNOPSIS

12        use File::Listing qw(parse_dir);
13        $ENV{LANG} = "C";  # dates in non-English locales not supported
14        foreach my $file (parse_dir(`ls -l`)) {
15            my ($name, $type, $size, $mtime, $mode) = @$file;
16            next if $type ne 'f'; # plain file
17            #...
18        }
19
20        # directory listing can also be read from a file
21        open my $listing, "zcat ls-lR.gz|";
22        $dir = parse_dir($listing, '+0000');
23

DESCRIPTION

25       This module exports a single function called "parse_dir", which can be
26       used to parse directory listings.
27

FUNCTIONS

29   parse_dir
30        my $dir = parse_dir( $listing );
31        my $dir = parse_dir( $listing, $time_zone );
32        my $dir = parse_dir( $listing, $time_zone, $type );
33        my $dir = parse_dir( $listing, $time_zone, $type, $error );
34        my @files = parse_dir( $listing );
35        my @files = parse_dir( $listing, $time_zone );
36        my @files = parse_dir( $listing, $time_zone, $type );
37        my @files = parse_dir( $listing, $time_zone, $type, $error );
38
39       The first parameter ($listing) is the directory listing to parse.  It
40       can be a scalar, a reference to an array of directory lines or a glob
41       representing a filehandle to read the directory listing from.
42
43       The second parameter ($time_zone) is the time zone to use when parsing
44       time stamps in the listing. If this value is undefined, then the local
45       time zone is assumed.
46
47       The third parameter ($type) is the type of listing to assume.
48       Currently supported formats are 'unix', 'apache' and 'dosftp'. The
49       default value is 'unix'. Ideally, the listing type should be determined
50       automatically.
51
52       The fourth parameter ($error) specifies how unparseable lines should be
53       treated. Values can be 'ignore', 'warn' or a code reference.  Warn
54       means that the perl warn() function will be called.  If a code
55       reference is passed, then this routine will be called and the return
56       value from it will be incorporated in the listing.  The default is
57       'ignore'.
58
59       Only the first parameter is mandatory.
60
61        # list context
62        foreach my $file (parse_dir($listing)) {
63            my($name, $type, $size, $mtime, $mode) = @$file;
64        }
65
66        # scalar context
67        my $dir = parse_dir($listing);
68        foreach my $file (@$dir) {
69            my($name, $type, $size, $mtime, $mode) = @$file;
70        }
71
72       The return value from parse_dir() is a list of directory entries.  In a
73       scalar context the return value is a reference to the list.  The
74       directory entries are represented by an array consisting of:
75
76       name
77           The name of the file.
78
79       type
80           One of: "f" file, "d" directory, "l" symlink, "?" unknown.
81
82       size
83           The size of the file.
84
85       time
86           The number of seconds since January 1, 1970.
87
88       mode
89           Bitmask a la the mode returned by "stat".
90

SEE ALSO

92       File::Listing::Ftpcopy
93           Provides the same interface but uses XS and the parser
94           implementation from "ftpcopy".
95

AUTHOR

97       Original author: Gisle Aas
98
99       Current maintainer: Graham Ollis <plicease@cpan.org>
100
101       Contributors:
102
103       Adam Kennedy
104
105       Adam Sjogren
106
107       Alex Kapranoff
108
109       Alexey Tourbin
110
111       Andreas J. Koenig
112
113       Bill Mann
114
115       Bron Gondwana
116
117       DAVIDRW
118
119       Daniel Hedlund
120
121       David E. Wheeler
122
123       David Steinbrunner
124
125       Erik Esterer
126
127       FWILES
128
129       Father Chrysostomos
130
131       Gavin Peters
132
133       Graeme Thompson
134
135       Grant Street Group
136
137       Hans-H. Froehlich
138
139       Ian Kilgore
140
141       Jacob J
142
143       Mark Stosberg
144
145       Mike Schilli
146
147       Ondrej Hanak
148
149       Peter John Acklam
150
151       Peter Rabbitson
152
153       Robert Stone
154
155       Rolf Grossmann
156
157       Sean M. Burke
158
159       Simon Legner
160
161       Slaven Rezic
162
163       Spiros Denaxas
164
165       Steve Hay
166
167       Todd Lipcon
168
169       Tom Hukins
170
171       Tony Finch
172
173       Toru Yamaguchi
174
175       Ville Skyttä
176
177       Yuri Karaban
178
179       Zefram
180
181       amire80
182
183       jefflee
184
185       john9art
186
187       mschilli
188
189       murphy
190
191       phrstbrn
192
193       ruff
194
195       sasao
196
197       uid39246
198
200       This software is copyright (c) 1996-2022 by Gisle Aas.
201
202       This is free software; you can redistribute it and/or modify it under
203       the same terms as the Perl 5 programming language system itself.
204
205
206
207perl v5.38.0                      2023-07-25                  File::Listing(3)
Impressum