The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Nile::File - Files and folders manager.

SYNOPSIS

        # 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);

DESCRIPTION

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);

Nile::File - Files and folders manager.

get()

        # 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()

        # 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.

File::Spec supported methods

        $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()

        # 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()

        # files_tree($dir, $match, $relative, $depth)
        @files = $self->me->file->files_tree("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.

folders()

        # 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.

folders_tree()

        # 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.

os()

        my $os = $self->me->file->os;

Returns the name of the operating system.

ds()

        my $ds = $self->me->file->ds;

Returns the directory separator of the operating system.

fileparse()

        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

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

dirname()

        my $ds = $self->me->file->dirname();

Returns the directory separator of the operating system. See File::Basename

path_info()

        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.

Bugs

This project is available on github at https://github.com/mewsoft/Nile.

HOMEPAGE

Please visit the project's homepage at https://metacpan.org/release/Nile.

SOURCE

Source repository is at https://github.com/mewsoft/Nile.

AUTHOR

Ahmed Amin Elsheshtawy, احمد امين الششتاوى <mewsoft@cpan.org> Website: http://www.mewsoft.com

COPYRIGHT AND LICENSE

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.