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