File::Listing(3) User Contributed Perl Documentation File::Listing(3)

# [SYNOPSIS](#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](#DESCRIPTION)

This module exports a single function called "parse\_dir", which can be used to parse directory listings.

# [FUNCTIONS](#FUNCTIONS)

## [parse\_dir](#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](#name)

The name of the file.

[type](#type)

One of: "f" file, "d" directory, "l" symlink, "?" unknown.

[size](#size)

The size of the file.

[time](#time)

The number of seconds since January 1, 1970.

[mode](#mode)

Bitmask a la the mode returned by "stat".

# [SEE ALSO](#SEE_ALSO)

[File::Listing::Ftpcopy](#File::Listing::Ftpcopy)

Provides the same interface but uses XS and the parser implementation from "ftpcopy".

2026-10-26 perl v5.44.0

---

Document: File::Listing(3pm) from perl-file-listing 6.16-r11 (Chainguard OS)
Source: https://github.com/PerlAlien/File-Listing
