NAME

Util::Medley::File - utility file methods

VERSION

version 0.010

SYNOPSIS

my $util = Util::Medley::File->new;

my $basename = $util->basename($path);
my $dirname  = $util->dirname($path);
my $newpath  = $util->trimSuffix($path);

my ($dir, $utilname, $suffix) = $util->parsePath($path);

$util->cp($src, $dest);
$util->mv($src, $dest);
$util->chmod($path);
$util->mkdir($path);
$util->rmdir($path);
$util->unlink($path);

my $prev_dir = $util->chdir($path);
my $type     = $util->fileType($path);
my @found    = $util->find($path);
my $cwd      = $util->getcwd;

DESCRIPTION

Provides frequently used file operation methods. Many of these are pass-through to another module. Others offer variations on the originals. All methods output debug logging statements when enabled. Any errors are bubbled up with Carp::confess(). Use eval as appropriate.

METHODS

basename

Pass-through to File::Path::basename().

usage:
$basename = $util->basename($path);

$basename = $util->basename(path => $path);
args:
path [Str]

The file path.

chdir

Pass-through to CORE::chdir(), but differs in that it returns the original dir.

usage:
$previous_dir = $util->chdir($path);

$previous_dir = $util->chdir(path => $path);
args:
$path [Str]

Destination directory.

chmod

Pass-through to CORE::chmod().

usage:
$util->chmod(0755, $path);

$util->chmod(perm => 0755, path => $path);
args:
perm [Str]

Numeric mode.

file [Str]

Location of the file to update.

cp

Pass-through to File::Copy::copy().

usage:
$util->cp($src, $dest);

$util->cp(src => $src, dest => $dest);
args:
src [Str]

Source file.

dest [Str]

Destination file.

dirname

Pass-through to File::Path::dirname().

usage:
$dir = $util->dirname($path);

$dir = $util->dirname(path => $path);
args:
path [Str]

The file path.

fileType

Get the filetype of a file.

usage:
$type = $util->fileType($path);

$type = $util->fileType(path => $path);
args:
path [Str]

Path of the file you wish to interrogate.

find

Pass-through to Path::Iterator::Rule. Returns a list of all files and directories.

usage:
@files = $util->find($dir);

@files = $util->find(dir => $dir);
args:
dir [Str]

The directory path you wish to search.

findFiles

Returns a list of all files under a given directory. Just a convenience wrapper around find.

usage:
@files = $util->findFiles($dir);

@files = $util->find(dir => $dir);
args:
dir [Str]

The directory path you wish to search.

findDirs

Returns a list of all directories under a given directory. Just a convenience wrapper around find.

usage:
@dirs = $util->findDirs($dir);

@dirs = $util->findDirs(dir => $dir);
args:
dir [Str]

The directory path you wish to search.

getcwd

Pass-through to Cwd::getcwd().

usage:
$cwd = $util->getcwd;

mkdir

Pass-through to File::Path::make_path().

usage:
$util->mkdir($path, [$perm]);

$util->mkdir(path => $path, [perm => $perm]);
args:
path [Str]

The directory path.

perm [Str]

Numeric mode.

mv

Pass-through to File::Copy::move().

usage:
$util->mv($src, $dest);

$util->mv(src => $src, dest => $dest);
args:
src [Str]

The source path.

dest [Str]

The destination path.

parsePath

Parse a file path into directory, filename, and extension. This is a pass-through to File::Basename::fileparse, but it additional trims the '.' from the extension and extraneous trailing /'s in the dir.

usage:
($dir, $name, $ext) = $util->parsePath($path);

($dir, $name, $ext) = $util->parsePath(path => $path);
args:
path [Str]

The file path for which you wish to parse.

rmdir

Delete a directory and any contents. Pass-through to File::Path::remove_tree().

usage:
$util->rmdir($dir);

$util->rmdir(dir => $dir);
args:
dir [Str]

Directory to remove.

trimExt

Trim the file extension from a filename.

usage:
$filename_no_ext = $util->trimExt($filename);

$filename_no_ext = $util->trimExt(name => $filename);
args:
name [Str]

The filename for which you want to remove the extension.

Pass-through to CORE::unlink().

usage:
$util->unlink($path);

$util->unlink(path => $path);
args:
path [Str]

Path of the file you wish to delete.