NAME
Util::Medley::File - utility file methods
VERSION
version 0.060
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().
chdir
Pass-through to CORE::chdir(), but differs in that it returns the original dir.
chmod
Pass-through to CORE::chmod().
cp
Pass-through to File::Copy::copy().
dirname
Pass-through to File::Path::dirname().
fileType
Get the filetype of a file.
find
Pass-through to Path::Iterator::Rule. Returns a list of all files and directories. Note this does NOT return the dir passed in.
- usage:
-
@files = $util->find($dir); @files = $util->find( dir => $dir, [minDepth => $minDepth], [maxDepth => $maxDepth] );
- args:
findFiles
Returns a list of all files under a given directory. Just a convenience wrapper around find.
- usage:
-
@files = $util->findFiles($dir); @files = $util->findFiles( dir => $dir, [minDepth => $minDepth], [maxDepth => $maxDepth], [extension => $extension] );
- args:
-
- dir [Str]
-
The directory path you wish to search.
- minDepth [Int]
-
Minimum directory depth to traverse. Not availble for positional based method.
- maxDepth [Int]
-
Maximum number of directeries (in terms of depth) to traverse. Not availble for positional based method.
- extension [Str]
-
Only return files with the given extension.
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, [minDepth => $minDepth], [maxDepth => $maxDepth] );
- args:
getcwd
Pass-through to Cwd::getcwd().
mkdir
Pass-through to File::Path::make_path().
mv
Pass-through to File::Copy::move().
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:
read
Just a pass-through to File::Slurp::read_file().
- usage:
-
$contents = $util->read($file, [0|1]); @contents = $util->read($file, [0|1]); $contents = $util->read(path => $file, trim => [0|1]); @contents = $util->read(path => $file, trim => [0|1]);
- args:
rmdir
Delete a directory and any contents. Pass-through to File::Path::remove_tree().
slurp (deprecated)
Just a pass-through to File::Slurp::read_file().
- usage:
-
$contents = $util->slurp($file, [0|1]); @contents = $util->slurp($file, [0|1]); $contents = $util->slurp(path => $file, trim => [0|1]); @contents = $util->slurp(path => $file, trim => [0|1]);
- args:
touch
Just a pass-through to File::Touch.
trimExt
Trim the file extension from a filename.
- usage:
-
$filename_no_ext = $util->trimExt($filename); $filename_no_ext = $util->trimExt(name => $filename);
- args:
unlink
Pass-through to built-in unlink().
which
Wrapper around File::Which::which()
- usage:
-
$path = $util->which($exe); @path = $util->which($exe); $path = $util->which(exe => $exe); @path = $util->which(exe => $exe);
- args:
write
Just a pass-through to File::Slurp::write_file().