| 1 |
NAME |
| 2 |
|
| 3 |
File::Listing - Parse directory listing |
| 4 |
|
| 5 |
VERSION |
| 6 |
|
| 7 |
version 6.16 |
| 8 |
|
| 9 |
SYNOPSIS |
| 10 |
|
| 11 |
use File::Listing qw(parse_dir); |
| 12 |
$ENV{LANG} = "C"; # dates in non-English locales not supported |
| 13 |
foreach my $file (parse_dir(`ls -l`)) { |
| 14 |
my ($name, $type, $size, $mtime, $mode) = @$file; |
| 15 |
next if $type ne 'f'; # plain file |
| 16 |
#... |
| 17 |
} |
| 18 |
|
| 19 |
# directory listing can also be read from a file |
| 20 |
open my $listing, "zcat ls-lR.gz|"; |
| 21 |
$dir = parse_dir($listing, '+0000'); |
| 22 |
|
| 23 |
DESCRIPTION |
| 24 |
|
| 25 |
This module exports a single function called parse_dir, which can be |
| 26 |
used to parse directory listings. |
| 27 |
|
| 28 |
FUNCTIONS |
| 29 |
|
| 30 |
parse_dir |
| 31 |
|
| 32 |
my $dir = parse_dir( $listing ); |
| 33 |
my $dir = parse_dir( $listing, $time_zone ); |
| 34 |
my $dir = parse_dir( $listing, $time_zone, $type ); |
| 35 |
my $dir = parse_dir( $listing, $time_zone, $type, $error ); |
| 36 |
my @files = parse_dir( $listing ); |
| 37 |
my @files = parse_dir( $listing, $time_zone ); |
| 38 |
my @files = parse_dir( $listing, $time_zone, $type ); |
| 39 |
my @files = parse_dir( $listing, $time_zone, $type, $error ); |
| 40 |
|
| 41 |
The first parameter ($listing) is the directory listing to parse. It |
| 42 |
can be a scalar, a reference to an array of directory lines or a glob |
| 43 |
representing a filehandle to read the directory listing from. |
| 44 |
|
| 45 |
The second parameter ($time_zone) is the time zone to use when parsing |
| 46 |
time stamps in the listing. If this value is undefined, then the local |
| 47 |
time zone is assumed. |
| 48 |
|
| 49 |
The third parameter ($type) is the type of listing to assume. Currently |
| 50 |
supported formats are 'unix', 'apache' and 'dosftp'. The default value |
| 51 |
is 'unix'. Ideally, the listing type should be determined |
| 52 |
automatically. |
| 53 |
|
| 54 |
The fourth parameter ($error) specifies how unparseable lines should be |
| 55 |
treated. Values can be 'ignore', 'warn' or a code reference. Warn means |
| 56 |
that the perl warn() function will be called. If a code reference is |
| 57 |
passed, then this routine will be called and the return value from it |
| 58 |
will be incorporated in the listing. The default is 'ignore'. |
| 59 |
|
| 60 |
Only the first parameter is mandatory. |
| 61 |
|
| 62 |
# list context |
| 63 |
foreach my $file (parse_dir($listing)) { |
| 64 |
my($name, $type, $size, $mtime, $mode) = @$file; |
| 65 |
} |
| 66 |
|
| 67 |
# scalar context |
| 68 |
my $dir = parse_dir($listing); |
| 69 |
foreach my $file (@$dir) { |
| 70 |
my($name, $type, $size, $mtime, $mode) = @$file; |
| 71 |
} |
| 72 |
|
| 73 |
The return value from parse_dir() is a list of directory entries. In a |
| 74 |
scalar context the return value is a reference to the list. The |
| 75 |
directory entries are represented by an array consisting of: |
| 76 |
|
| 77 |
name |
| 78 |
|
| 79 |
The name of the file. |
| 80 |
|
| 81 |
type |
| 82 |
|
| 83 |
One of: f file, d directory, l symlink, ? unknown. |
| 84 |
|
| 85 |
size |
| 86 |
|
| 87 |
The size of the file. |
| 88 |
|
| 89 |
time |
| 90 |
|
| 91 |
The number of seconds since January 1, 1970. |
| 92 |
|
| 93 |
mode |
| 94 |
|
| 95 |
Bitmask a la the mode returned by stat. |
| 96 |
|
| 97 |
SEE ALSO |
| 98 |
|
| 99 |
File::Listing::Ftpcopy |
| 100 |
|
| 101 |
Provides the same interface but uses XS and the parser implementation |
| 102 |
from ftpcopy. |
| 103 |
|
| 104 |
AUTHOR |
| 105 |
|
| 106 |
Original author: Gisle Aas |
| 107 |
|
| 108 |
Current maintainer: Graham Ollis <[email protected]> |
| 109 |
|
| 110 |
Contributors: |
| 111 |
|
| 112 |
Adam Kennedy |
| 113 |
|
| 114 |
Adam Sjogren |
| 115 |
|
| 116 |
Alex Kapranoff |
| 117 |
|
| 118 |
Alexey Tourbin |
| 119 |
|
| 120 |
Andreas J. Koenig |
| 121 |
|
| 122 |
Bill Mann |
| 123 |
|
| 124 |
Bron Gondwana |
| 125 |
|
| 126 |
DAVIDRW |
| 127 |
|
| 128 |
Daniel Hedlund |
| 129 |
|
| 130 |
David E. Wheeler |
| 131 |
|
| 132 |
David Steinbrunner |
| 133 |
|
| 134 |
Erik Esterer |
| 135 |
|
| 136 |
FWILES |
| 137 |
|
| 138 |
Father Chrysostomos |
| 139 |
|
| 140 |
Gavin Peters |
| 141 |
|
| 142 |
Graeme Thompson |
| 143 |
|
| 144 |
Grant Street Group |
| 145 |
|
| 146 |
Hans-H. Froehlich |
| 147 |
|
| 148 |
Ian Kilgore |
| 149 |
|
| 150 |
Jacob J |
| 151 |
|
| 152 |
Mark Stosberg |
| 153 |
|
| 154 |
Mike Schilli |
| 155 |
|
| 156 |
Ondrej Hanak |
| 157 |
|
| 158 |
Peter John Acklam |
| 159 |
|
| 160 |
Peter Rabbitson |
| 161 |
|
| 162 |
Robert Stone |
| 163 |
|
| 164 |
Rolf Grossmann |
| 165 |
|
| 166 |
Sean M. Burke |
| 167 |
|
| 168 |
Simon Legner |
| 169 |
|
| 170 |
Slaven Rezic |
| 171 |
|
| 172 |
Spiros Denaxas |
| 173 |
|
| 174 |
Steve Hay |
| 175 |
|
| 176 |
Todd Lipcon |
| 177 |
|
| 178 |
Tom Hukins |
| 179 |
|
| 180 |
Tony Finch |
| 181 |
|
| 182 |
Toru Yamaguchi |
| 183 |
|
| 184 |
Ville Skyttä |
| 185 |
|
| 186 |
Yuri Karaban |
| 187 |
|
| 188 |
Zefram |
| 189 |
|
| 190 |
amire80 |
| 191 |
|
| 192 |
jefflee |
| 193 |
|
| 194 |
john9art |
| 195 |
|
| 196 |
mschilli |
| 197 |
|
| 198 |
murphy |
| 199 |
|
| 200 |
phrstbrn |
| 201 |
|
| 202 |
ruff |
| 203 |
|
| 204 |
sasao |
| 205 |
|
| 206 |
uid39246 |
| 207 |
|
| 208 |
COPYRIGHT AND LICENSE |
| 209 |
|
| 210 |
This software is copyright (c) 1996-2022 by Gisle Aas. |
| 211 |
|
| 212 |
This is free software; you can redistribute it and/or modify it under |
| 213 |
the same terms as the Perl 5 programming language system itself. |
| 214 |
|