File::DirList(3pm)

✨ NAME ✨

File::DirList β€” bestie, it hands you a sorted list of what's inside a directory πŸ’…

Version 0.04 (yes she's been around a minute and she still slays)


πŸŽ€ SYNOPSIS πŸŽ€

use File::DirList;
#
my @list = File::DirList::list('.', 'dn', 1, 0);

See? One line. Iconic. πŸ‘‘


πŸ¦‹ DESCRIPTION πŸ¦‹

okay so this module is your girl for getting a list of directory content. That's the whole vibe. Under the hood it's literally just a simple wrapper around DirHandle and sort() β€” no cap, it's not doing anything shady, it's just making the sorting cute for you. 😌

She's got two methods, and we're gonna go through both, no skipping, because you deserve the full lore.

This one produces a list, and it takes 5 parameters. Five. Count 'em. πŸ–οΈ

  • $dirName β€” the name of the directory you wanna list. That's it, that's the job.
  • $sortMode β€” this is the one that describes how the list should get sorted. It's a string containing the following symbols, and here's the tea: uppercase means reverse sort. πŸ”„ So lowercase and uppercase are NOT the same girl.
    • "d" or "D" β€” "Directory" sort. d means all the directories will precede files, D means reverse.
    • "n" or "N" β€” sort by file (or subdirectory) name.
    • "i" or "I" β€” same as 'n' but case insensitive.
    • "m" or "M" β€” sort by modification time.
    • "c" or "C" β€” sort by creation time.
    • "a" or "A" β€” sort by access time.
    • "s" or "S" β€” sort by size.

And here's the part you gotta know bestie: $sortMode is interpreted from left to right, like reading a text from your situationship. If the first comparison produces an equal result, the next one is used. So for example, the string 'din' produces a list where all the directories precede files, and directories and files are sorted by name case insensitively, with lowercase letters preceding upper case. Periodt. πŸ’…

  • $noLinks β€” if "true", symbolic links will not be examined. Set it on platforms without symlink support. (Real ones without symlinks, this one's for you 🫢)
  • $hideDotFiles β€” if "true", 'dot' files will not be reported. They're hidden, babes, we respect their privacy. πŸ™ˆ
  • $showSelf β€” if "true", the '.' directory entry will be reported. She's showing up to her own party. ✨

The returned value is an array reference, sorted exactly as described by $sortMode.

And the array elements? They're array references too, each one representing an item. (Nested arrays, we love a little structure. πŸͺ†)

🌸 the individual item's array β€” 17 elements, let's go

  • "[0..12]" β€” the result of stat() for this item. For valid symbolic links, the stat of the target item is returned. iykyk.
  • "[13]" β€” the name of the item.
  • "[14]" β€” is item a directory? Contains 0 for non-directory items, 1 for directories, 2 for '..', 3 for '.'. This one gets used by the "d or D" sorting. πŸ‘‘
  • "[15]" β€” is item a link? 0 for non-links, 1 for valid links, "-1" for invalid links.
  • "[16]" β€” link target. "undef" for non-links, target path for links.
heads up: [15] and [16] are set to non-link if $examineLinks is "false".

πŸ’œ sortList($list, $sortMode)

This one is used to re-sort a list produced by "list()". Like a glow-up for an existing list, no reshuffling the whole directory needed. ✨

Parameters are:

  • $lis β€” reference to a list produced by "list()". (yes it's spelled $lis in the docs, and honestly? she's doing her best, we don't fix her 🫢)
  • $sortMode β€” the sorting rules.

The return value is similar to "list()". Same energy, new order. πŸŽ€


🌈 EXPORT 🌈

None by default. Nothing gets yeeted into your namespace unless you ask. Consent first, always. πŸ’…


⭐ SEE ALSO ⭐

DirHandle, stat, lstat, sort β€” the whole friend group. Go say hi. 🫢


πŸ‘‘ AUTHOR πŸ‘‘

Daniel Podolsky, <tpaba@cpan.org> β€” the legend herself. 🫑


Copyright (C) 2006 by Daniel Podolsky, <tpaba@cpan.org>

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.4 or, at your option, any later version of Perl 5 you may have available.


and that's the whole page bestie!! this lil doc was brought to you by perl v5.36.0, dated 2022-10-13, for File::DirList(3pm) β€” go sort something cute, mwah πŸ’‹πŸŒΈπŸ’…

πŸ“¦ where this page comes from