NAME

Dir::Split - Split the files of a directory to subdirectories.

SYNOPSIS

use Dir::Split;

# define options
%options = ( verbose =>   0,

             sub_dir => { identifier          =>    'system',
                          file_limit          =>         '2',
                          file_sort           =>         '+',
             },

             suffix =>  { separator           =>         '.',
                          length              =>           4,
                          continue_num        =>         'y',
             },
);

# create object
$dir = Dir::Split->new (\%options);

# set source & target dirs
$source_dir = '/var/tmp/src';
$target_dir = '/var/tmp/target';

# split files to subdirs
$files_moved = $dir->split (\$source_dir, \$target_dir);

# changes the subdir identifier
$dir->{'sub_dir'}{'identifier'} = 'test';

# split files to subdirs
$files_moved = $dir->split (\$source_dir, \$target_dir);

DESCRIPTION

Dir::Split moves files from a source directory to numbered subdirectories within a target directory.

METHODS

new ( \%options )

Object constructor.

$dir = Dir::Split->new (\%options);

%options contains the options that will influence the splitting process.

%options = ( verbose =>   0,

             sub_dir => { identifier          =>    'system',
                          file_limit          =>         '2',
                          file_sort           =>         '+',
             },

             suffix =>  { continue_num        =>         'y',
                          separator           =>         '.',
                          length              =>           4,
             },
);

verbose sets the verbosity (see table VERBOSITY MODES); if enabled, mkpath will output the pathes on creating subdirectories.

sub_dir/identifier will affect the prefix of each subdirectory. sub_dir/file_limit sets the limit of files per each subdirectory. sub_dir/file_sort defines the sorting order of files (see table SORT MODES).

suffix/continue_num defines whether the numbering shall be continued where it previously stopped or start at 1 (see table CONTINUE NUMBERING MODES). suffix/separator contains the string that separates the identifier from the suffix. suffix/length is an non-floating-point integer that sets the amount of zeros to be added to the subdirectory numbering.

Differing identifiers or separators do affect the numbering e.g. systm- does not equal system-, system_ does not equal system-. file_limit, file_sort and separator options have no influence on decisions whether the numbering shall be continued or not.

VERBOSITY MODES
  0  disabled
  1  enabled

SORT MODES
  +  ascending sort order
  -  descending sort order

CONTINUE NUMBERING MODES
  y   yes
  ''  no

split ( \$source_dir, \$target_dir )

Split the files to subdirectories.

$files_moved = $dir->split (\$source_dir, \$target_dir);

$source_dir specifies the source directory.

$target_dir specifies the target directory.

Returns the amount of files that have been successfully moved; if none, it will return undef.

EXAMPLE

Assuming the source directory '/var/tmp/src' contains 9 files, the directory tree in the target directory '/var/tmp/target' will look as following:

+ /var/tmp/target
+- system.0001 / 2 file(s)
+- system.0002 / 2 "
+- system.0003 / 2 "
+- system.0004 / 2 "
+- system.0005 / 1 "

DEPENDENCIES

Perl 5.6.1; File::Copy, File::Path, File::Spec.

CAVEATS

Recursive source directory processing is not supported; existing directories within the source directory will be ignored.

SEE ALSO

perl(1)

LICENSE

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

AUTHOR

Steven Schubiger