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

NAME

6       File::Listing - parse directory listing
7

SYNOPSIS

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

DESCRIPTION

22       This module exports a single function called "parse_dir", which can be
23       used to parse directory listings.
24

FUNCTIONS

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

SEE ALSO

89       File::Listing::Ftpcopy
90           Provides the same interface but uses XS and the parser
91           implementation from "ftpcopy".
92
94       Copyright 1996-2010, Gisle Aas Copyright 2020 Graham Ollis
95
96       Based on lsparse.pl (from Lee McLoughlin's ftp mirror package) and
97       Net::FTP's parse_dir (Graham Barr).
98
99       This library is free software; you can redistribute it and/or modify it
100       under the same terms as Perl itself.
101
102
103
104perl v5.32.0                      2020-10-01                  File::Listing(3)
Impressum