| File-is documentation | view source | Contained in the File-is distribution. |
File::is - file is older? oldest? is newer? newest? similar? the same?
use File::is;
# return if F<file1> is newer than F<file2> or F<file3>.
return
if File::is->newer('file1', 'file2', 'file3');
# do something if F<path1/file1> is older than F<file2> or F<path3/file3>.
do_some_work()
if File::is->older([ 'path1', 'file1'], 'file2', [ 'path3', 'file3' ]);
This module is a result of /me not wanting to write:
if ($(stat('filename'))[9] < $(stat('tmp/other-filename'))[9]) { do_someting(); };
Instead I wrote a module with ~80 lines of code and ~90 lines of tests
for it... So how is the module different from the above if? Should be
reusable, has more functionality, should be clear from the code it self
what the condition is doing and was fun to play with it. Another advantage
is that the file names can be passed as array refs. In this case
catfile in File::Spec is used to construct the filename. The resulting code
is:
if (File::is->older('filename', [ 'tmp', 'other-filename' ])) { do_something(); };
Returns true/false if the $primary_filename is newer (has modification
time-stamp recent) then any of the rest passed as argument.
Returns true/false if the $primary_filename is newest (has the biggest
modification time-stamp) compared to the rest of the passed filenames.
Returns true/false if the $primary_filename is older (has the later
modification time-stamp) then any of the rest passed as argument.
Returns true/false if the $primary_filename is oldest (has the latest
modification time-stamp) compared to the rest of the passed filenames.
Returns true/false if the $primary_filename has the same size and modification
time-stamp than any of the rest of the passed filenames.
Returns true/false if the $primary_filename has the same inode and dev
(is hard link) to any of the rest of the passed filenames.
NOTE: see http://perlmonks.org/?node_id=859612, File::Same
Returns true/false if the $primary_filename is bigger (has the bigger
size) then any of the rest passed as argument.
Returns true/false if the $primary_filename is biggest (has the biggest
size) compared to the rest of the passed filenames.
Returns true/false if the $primary_filename is smaller (has the smaller
size) then any of the rest passed as argument.
Returns true/false if the $primary_filename is smallest (has the smallest
size) compared to the rest of the passed filenames.
Call/use at your own risk ;-)
Accepts one or more arguments. It passes them to <File::Spec-catfile()>>
dereferencing the array if one argument array ref is passed.
Example:
_construct_filename('file') => 'file'
_construct_filename([ 'folder', 'file' ]) => File::Spec->catfile('folder', 'file');
_construct_filename('folder', 'file') => File::Spec->catfile('folder', 'file');
This function is called on every argument passed to cmp methods (newer, smaller, older, ...).
This function is called by all of the public newer(), smaller(), older(),
... methods do loop through files and do some cmp on them.
Jozef Kutej, <jkutej at cpan.org>
The following people have contributed to the File::is by committing their code, sending patches, reporting bugs, asking questions, suggesting useful advises, nitpicking, chatting on IRC or commenting on my blog (in no particular order):
Ronald Fischer
Please report any bugs or feature requests to bug-file-is at rt.cpan.org, or through
the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=File-is. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
You can find documentation for this module with the perldoc command.
perldoc File::is
You can also look for information at:
Copyright 2010 jkutej@cpan.org
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
| File-is documentation | view source | Contained in the File-is distribution. |