Directory - an object representing a directory
use Directory;
# OBJECT CONSTRUCTION
my $dir = Directory.new('/some/dir'); # relative paths OK, too
my $dir = Directory.new('~');
my $dir = Directory.new(); # current working directory, '.'
# METHODS
my $bool = Directory.new('/some/dir').exists;
my $bool = Directory.new('/some/dir').is-empty;
my @entries = Directory.new('/some/dir').list;
my $bool = Directory.new('/some/dir').mktree;
my $bool = Directory.new('/some/dir').create;
my $bool = Directory.new('/some/dir').rmtree;
my $bool = Directory.new('/some/dir').empty-directory;
my $path = Directory.new('/some/dir').path;
my $dir = Directory.new('/some/dir').open;
my $sequence = $dir.dir;
$dir.close;
A Directory object wraps an IO::Dir object as well as the the subroutines found in the File::Directory::Tree distribution. The module aims to make working with directories simpler. The primary motivation was for type constraining class attributes representing directories.
Creates a new Directory object from the $path
supplied or with the path to the current working directory if no $path
is given. An error is thrown if a file already exists at the $path
. A path beginning with the ~
character is replaced with the value of the $*HOME
> variable, if it contains a value.
Returns a boolean value of True
if the directory exists, False
otherwise.
Returns a boolean value of True
if the directory is empty, False
otherwise.
Returns an array of IO::Path
s for each file and directory in the Directory object's path. Pass :Str
to return strings instead and :absolute
to return absolute paths.
Returns the IO::Path object for the Directory object.
Opens the Directory object with the open
method from IO::Dir
. Unlike with the IO::Dir.open
, no path is passed to the method.
Runs the dir
method from IO::Dir
, returning a sequence of IO paths for files and directories contained by the Directory object. Pass :Str
to return strings instead and :absolute
to return absolute paths.
The Directory object must be opened with the open
method before running this method.
Closes the Directory object with the close
method from IO::Dir
A wrapper for the File::Directory::Tree's mktree command.
Synonym for mktree
method.
A wrapper for the File::Directory::Tree's rmtree command.
A wrapper for the File::Directory::Tree's empty-directory command.
Steve Dondley [email protected]
Copyright 2023 Steve Dondley
This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.