function ok = newerfile1than2( file1, file2, verbose )
% NEWERFILE1THAN2 - Returns true if one file is more recent than another
% OK = NEWERFILE1THAN2 (FILE1, FILE2)
% OK - True if first file is more recent than second file.
% (optional inputs) FILE1 and FILE2 are filename strings
% The last-modified date/time is used, not the creation date.
% NEWERFILE1THAN2 (FILE1, FILE2, VERBOSE)
% (optional input) VERBOSE - flag whether messages are displayed on the command line
% (default 1 (on), 0 for off)
%
% If files dates are the same, returns true.
%
% Paul Macey
% 2006-01-11
ok = [];
if nargin < 1
[f,p] = uigetfile('Select first file');
if f == 0, return, end
file1 = [p,f];
end
if nargin < 2
[f,p] = uigetfile('Select second file');
if f == 0, return, end
file2 = [p,f];
end
if nargin < 3
verbose = 1;
end
if ~exist(file1) | ~exist(file2)
if verbose
MsgBox('Files don''t both exist!','File date comparison','warn')
end
return
end
d1 = dir(file1);
d2 = dir(file2);
ok = datenum(d1.date) >= datenum(d2.date);
if verbose
disp(' ')
disp([file1,' (',d1.date,')'])
disp(' ')
if ok
disp('is newer than ')
else
disp('is older than ')
end
disp(' ')
disp([file2,' (',d2.date,')'])
disp(' ')
end
if nargout == 0
clear ok
end