Nile::File - Files and folders manager.
# get the file content as a single string. $content = $self->me->file->get($file); # get the file content as an array of lines. @lines = $self->me->file->get($file); # get list of specific files in a folder @files = $self->me->file->files("c:/apache/htdocs/nile/", "*.pm, *.cgi"); # get list of specific files in a folder recursively # files_tree($dir, $match, $relative, $depth) @files = $self->me->file->files_tree("c:/apache/htdocs/nile/", "*.pm, *.cgi"); # get list of sub folders in a folder #folders($dir, $match, $relative) @folders = $self->file->folders("c:/apache/htdocs/nile/", "", 1); # get list of sub folders in a folder recursively #folders_tree($dir, $match, $relative, $depth) @folders = $self->file->folders_tree("c:/apache/htdocs/nile/", "", 1);
The file object provides tools for reading files, folders, and most of the functions in the modules File::Spec and File::Basename.
to get file content as single string or array of strings:
$content = $self->me->file->get($file); @lines = $self->me->file->get($file);
supports options same as File::Slurp.
To get list of files in a specific folder:
#files($dir, $match, $relative) @files = $self->me->file->files("c:/apache/htdocs/nile/", "*.pm, *.cgi"); #files_tree($dir, $match, $relative, $depth) @files = $self->me->file->files_tree("c:/apache/htdocs/nile/", "*.pm, *.cgi"); #folders($dir, $match, $relative) @folders = $self->file->folders("c:/apache/htdocs/nile/", "", 1); #folders_tree($dir, $match, $relative, $depth) @folders = $self->file->#folders_tree("c:/apache/htdocs/nile/", "", 1);
# file($file, $options) $content = $self->me->file->get("/path/file.txt"); @lines = $self->me->file->get("/path/file.txt"); $bin = $self->me->file->get("/path/file.bin", binmode => ':raw'); $utf = $self->me->file->get("/path/file.txt", binmode => ':utf8');
Reads file contents into a single variable or an array. This method is a wrapper around File::Slurp read_file method.
# put($file, $options) $self->me->file->put($file, @data); $self->me->file->put($file, {binmode => ':raw'}, $buffer); $self->me->file->put($file, \$buffer); # the same as $self->me->file->put($file, $buffer); $self->me->file->put($file, \@lines) ; # the same as $self->me->file->put($file, @lines) ;
Writes contents into a file. This method is a wrapper around File::Slurp write_file method. The first argument is the filename. The second argument is an optional hash reference and it contains key/values that can modify the behavior of write_file. The rest of the argument list is the data to be written to the file.
$self->me->file->canonpath; $self->me->file->catdir $self->me->file->catfile $self->me->file->curdir $self->me->file->rootdir $self->me->file->updir $self->me->file->no_upwards $self->me->file->file_name_is_absolute $self->me->file->path $self->me->file->devnull $self->me->file->tmpdir $self->me->file->splitpath $self->me->file->splitdir $self->me->file->catpath $self->me->file->abs2rel $self->me->file->rel2abs $self->me->file->case_tolerant
Wrapper methods around File::Spec functions.
# files($dir, $match, $relative) @files = $self->me->file->files("c:/apache/htdocs/nile/", "*.pm, *.cgi");
Returns a list of files in a specific folder. The first argument is the path, the second argument is the filename match if not set will match all files, the third argument is the relative flag, if set will include the relative path of the files.
# files_tree($dir, $match, $relative, $depth) @files = $self->me->file->files_tree("c:/apache/htdocs/nile/", "*.pm, *.cgi");
# get list of sub folders in a folder # folders($dir, $match, $relative) @folders = $self->file->folders("c:/apache/htdocs/nile/", "", 1); # get list of sub folders in a folder recursively #folders_tree($dir, $match, $relative, $depth) @folders = $self->file->$folders_tree("c:/apache/htdocs/nile/", "", 1);
Returns a list of sub folders in a folder.
# get list of sub folders in a folder recursively #folders_tree($dir, $match, $relative, $depth) @folders = $self->file->folders_tree("c:/apache/htdocs/nile/", "", 1);
Returns list of sub folders in a folder recursively.
my $os = $self->me->file->os;
Returns the name of the operating system.
my $ds = $self->me->file->ds;
Returns the directory separator of the operating system.
my ($filename, $dirs, $suffix) = $self->me->file->fileparse($path); my ($filename, $dirs, $suffix) = $self->me->file->fileparse($path, @suffixes); my $filename = $self->me->file->fileparse($path, @suffixes);
Splits a file path into its $dirs, $filename and (optionally) the filename $suffix. See File::Basename
my $filename = $self->me->file->basename($path); my $filename = $self->me->file->basename($path, @suffixes);
Returns the last level of a filepath even if the last level is clearly directory. In effect, it is acting like pop() for paths. See File::Basename
my $ds = $self->me->file->dirname();
Returns the directory separator of the operating system. See File::Basename
my ($name, $dir, $ext, $name_$ext) = $self->me->file->path_info($path);
Splits a file path into its $dir, $name, filename $suffix, and name with suffix.
This project is available on github at https://github.com/mewsoft/Nile.
Please visit the project's homepage at https://metacpan.org/release/Nile.
Source repository is at https://github.com/mewsoft/Nile.
Ahmed Amin Elsheshtawy, احمد امين الششتاوى <mewsoft@cpan.org> Website: http://www.mewsoft.com
Copyright (C) 2014-2015 by Dr. Ahmed Amin Elsheshtawy احمد امين الششتاوى mewsoft@cpan.org, support@mewsoft.com, https://github.com/mewsoft/Nile, http://www.mewsoft.com
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Nile, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Nile
CPAN shell
perl -MCPAN -e shell install Nile
For more information on module installation, please visit the detailed CPAN module installation guide.