Util::Medley::File - utility file methods
version 0.040
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;
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.
Pass-through to File::Path::basename().
$basename = $util->basename($path); $basename = $util->basename(path => $path);
The file path.
Pass-through to CORE::chdir(), but differs in that it returns the original dir.
$previous_dir = $util->chdir($path); $previous_dir = $util->chdir(path => $path);
Destination directory.
Pass-through to CORE::chmod().
$util->chmod(0755, $path); $util->chmod(perm => 0755, path => $path);
Numeric mode.
Location of the file to update.
Pass-through to File::Copy::copy().
$util->cp($src, $dest); $util->cp(src => $src, dest => $dest);
Source file.
Destination file.
Pass-through to File::Path::dirname().
$dir = $util->dirname($path); $dir = $util->dirname(path => $path);
Get the filetype of a file.
$type = $util->fileType($path); $type = $util->fileType(path => $path);
Path of the file you wish to interrogate.
Pass-through to Path::Iterator::Rule. Returns a list of all files and directories. Note this does NOT return the dir passed in.
@files = $util->find($dir); @files = $util->find( dir => $dir, [minDepth => $minDepth], [maxDepth => $maxDepth] );
The directory path you wish to search.
Minimum directory depth to traverse. Not availble for positional based method.
Maximum directory depth to traverse. Not availble for positional based method.
Returns a list of all files under a given directory. Just a convenience wrapper around find.
@files = $util->findFiles($dir); @files = $util->findFiles( dir => $dir, [minDepth => $minDepth], [maxDepth => $maxDepth], [extension => $extension] );
Maximum number of directeries (in terms of depth) to traverse. Not availble for positional based method.
Only return files with the given extension.
Returns a list of all directories under a given directory. Just a convenience wrapper around find.
@dirs = $util->findDirs($dir); @dirs = $util->findDirs( dir => $dir, [minDepth => $minDepth], [maxDepth => $maxDepth] );
Pass-through to Cwd::getcwd().
$cwd = $util->getcwd;
Pass-through to File::Path::make_path().
$util->mkdir($path, [$perm]); $util->mkdir(path => $path, [perm => $perm]);
The directory path.
Pass-through to File::Copy::move().
$util->mv($src, $dest); $util->mv(src => $src, dest => $dest);
The source path.
The destination path.
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.
($dir, $name, $ext) = $util->parsePath($path); ($dir, $name, $ext) = $util->parsePath(path => $path);
The file path for which you wish to parse.
Just a pass-through to File::Slurp::read_file().
$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]);
File to read.
Trim newlines. Default 0.
Delete a directory and any contents. Pass-through to File::Path::remove_tree().
$util->rmdir($dir); $util->rmdir(dir => $dir);
Directory to remove.
$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]);
File to slurp.
Just a pass-through to File::Touch.
$util->touch($file); $util->touch(path => $file);
File or directory to touch.
Trim the file extension from a filename.
$filename_no_ext = $util->trimExt($filename); $filename_no_ext = $util->trimExt(name => $filename);
The filename for which you want to remove the extension.
Pass-through to built-in unlink().
$util->unlink($path); $util->unlink(path => $path);
Path of the file you wish to delete.
Wrapper around File::Which::which()
$path = $util->which($exe); @path = $util->which($exe); $path = $util->which(exe => $exe); @path = $util->which(exe => $exe);
Name of the executable you are searching for.
Just a pass-through to File::Slurp::write_file().
$util->write($file, $content, [ {opts} ]); $util->write(path => $file, content => $content, [ opts => {} ]);
File to write.
File content.
Additional opts to pass to write_file.
To install Util::Medley, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Util::Medley
CPAN shell
perl -MCPAN -e shell install Util::Medley
For more information on module installation, please visit the detailed CPAN module installation guide.