The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

CTK::Plugin::File - File plugin

VERSION

Version 1.03

SYNOPSIS

    use CTK;
    my $ctk = CTK->new(
            plugins => "file",
        );

    my $n = $ctk->fcopy(
        -dirsrc => "/path/to/source/dir", # Source directory
        -dirdst => "/path/to/destination/dir", # Destination directory
        -glob   => "*.conf",
        -format => '[FILE].copy', # Format. Default: [FILE]
        -uniq   => 0, # 0 -- off; 1 -- on
    );

    my $n = $ctk->fmove(
        -dirsrc => "/path/to/source/dir", # Source directory
        -dirdst => "/path/to/destination/dir", # Destination directory
        -glob   => "*.conf",
        -format => '[FILE]', # Format. Default: [FILE]
        -uniq   => 0, # 0 -- off; 1 -- on
    );

    my $n = $ctk->fremove(
        -dirsrc => "/path/to/source/dir", # Source directory
        -glob   => "*.conf",
    );

    my $n = $ctk->fsplit(
        -dirsrc => "/path/to/source/dir", # Source directory
        -dirdst => "/path/to/destination/dir", # Destination directory
        -glob   => "*.txt",
        -lines  => 3,
        -format => '[FILE].part[PART]', # Format. Default: [FILE].part[PART]
    )

    my $n = $ctk->fjoin(
        -dirsrc => "/path/to/source/dir", # Source directory
        -dirdst => "/path/to/destination/dir", # Destination directory
        -glob   => "*.txt",
        -outfile=> "join.txt",
        -binmode=> "off",
        -eol    => "\n",
    );

DESCRIPTION

File plugin

METHODS

fcopy
    my $n = $ctk->fcopy(
        -dirsrc => "/path/to/source/dir", # Source directory
        -dirdst => "/path/to/destination/dir", # Destination directory
        -glob   => "*.conf",
        -format => '[FILE].copy', # Format. Default: [FILE]
        -uniq   => 0, # 0 -- off; 1 -- on
    );

Copies files from the source directory to the destination directory and returns how many files was copied

-dirin, -in, -dirsrc, -src, -source

Specifies source directory

Default: current directory

-dirout, -out, -dirdst, -dst, -target

Specifies destination directory

Default: current directory

-list, -mask, -glob, -file, -files, -regexp
    -list => [qw/ file1.txt file2.txt file3.* /]

List of files or globs

    -glob => "file.*"

Glob pattern

    -file => "file1.txt"

Name of file

    -regexp => qr/\.(cgi|pl)$/i

Regexp

Default: undef (all files)

-format, -callback, -cb
    -format => "[COUNT]_[FILE].copy.[TIME]"

Specifies format for output file

    -callback => sub {
        my $file_name = shift;
        my $file_number = shift;
        ...
        return $file_name;
    }

Callbacks allows you to modify the name of the output file manually

Default: "[FILE]"

-uniq, -unique

Unique mode

Default: off

Replacing keys: FILE, COUNT, TIME

fjoin
    my $n = $ctk->fjoin(
        -dirsrc => "/path/to/source/dir", # Source directory
        -dirdst => "/path/to/destination/dir", # Destination directory
        -glob   => "*.txt",
        -outfile=> "join.txt",
        -binmode=> "off",
        -eol    => "\n",
    );

Join group of files (by mask from source directory) to one big file (concatenate). File writes to destination directory by output file name (fout)

    perl -MCTK::Command -e "fjoin(-mask=>qr/txt$/, -fout=>'foo.txt')" -- *

This is new features, added since CTK 1.18

-dirin, -in, -dirsrc, -src, -source

Specifies source directory

Default: current directory

-dirout, -out, -dirdst, -dst, -destination

Specifies destination directory

Default: current directory

-list, -mask, -glob, -files, -regexp
    -list => [qw/ file1.txt file2.txt file3.* /]

List of files or globs

    -glob => "file.*"

Glob pattern

    -file => "file1.txt"

Name of file

    -regexp => qr/\.(cgi|pl)$/i

Regexp string (recommended)

Default: undef (all files)

-file, -filename, -fileout, -target

Specifies target file

Required parameter

-binmode

Turns on binary mode of processing file. Default is textmode - will read each line of input file and write it to output file

Default: no (textmode)

-eol, -newline, -nl, -crlf

Specifies end-of-line character for lines preprocessing

Default: \n

fmove
    my $n = $ctk->fmove(
        -dirsrc => "/path/to/source/dir", # Source directory
        -dirdst => "/path/to/destination/dir", # Destination directory
        -glob   => "*.conf",
        -format => '[FILE]', # Format. Default: [FILE]
        -uniq   => 0, # 0 -- off; 1 -- on
    );

Movies files from the source directory to the destination directory and returns how many files was moved

Format of arguments see "fcopy"

fremove
    my $n = $ctk->fremove(
        -dir    => "/path/to/source/dir", # Source directory
        -glob   => "*.conf",
    );

Removing files from the source directory

Format of arguments see "fcopy"

fsplit
    my $n = $ctk->fsplit(
        -dirsrc => "/path/to/source/dir", # Source directory
        -dirdst => "/path/to/destination/dir", # Destination directory
        -glob   => "*.txt",
        -lines  => 3,
        -format => '[FILE].part[PART]', # Format. Default: [FILE].part[PART]
    )

Split group of files to parts

-dirin, -in, -dirsrc, -src, -source

Specifies source directory

Default: current directory

-dirout, -out, -dirdst, -dst, -target

Specifies destination directory

Default: current directory

-list, -mask, -glob, -file, -files, -regexp
    -list => [qw/ file1.txt file2.txt file3.* /]

List of files or globs

    -glob => "file.*"

Glob pattern

    -file => "file1.txt"

Name of file

    -regexp => qr/\.(cgi|pl)$/i

Regexp

Default: undef (all files)

-limit, -lines, -rows, -n
    -lines => 5

Splits file by 5 lines

-format, -callback, -cb
    -format => "[COUNT]_[FILE].copy[TIME].part[PART]"

Specifies format for output file

    -callback => sub {
        my $input_file_name = shift;
        my $input_file_number = shift;
        my $output_file_number = shift; # Part number
        ...
        return $file_name;
    }

Callbacks allows you to modify the name of the output file manually

Default: "[FILE].part[PART]"

Replacing keys: FILE, COUNT, TIME, PART

REPLACING KEYS

FILE

Path and filename

FILENAME

Filename only

FILEEXT

File extension only

COUNT

Current number of file in sequence (for fcopy and fmove methods)

For fsplit method please use perl mask %i

TIME

Current time value (unix-time format, time())

HISTORY

See Changes file

DEPENDENCIES

CTK, CTK::Plugin, File::Find, File::Copy, Cwd

TO DO

See TODO file

BUGS

* none noted

SEE ALSO

CTK, CTK::Plugin

AUTHOR

Serż Minus (Sergey Lepenkov) https://www.serzik.com <abalama@cpan.org>

COPYRIGHT

Copyright (C) 1998-2022 D&D Corporation. All Rights Reserved

LICENSE

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See LICENSE file and https://dev.perl.org/licenses/