from
last_modified
by Matthew Foster
Return the last modified file(s) in a given directory or glob.
|
| last_modified(path, num) |
function ff = last_modified(path, num)
% ff = last_modified(path, varargin) Return the names of the last
% modified files in path.
%
% Works by searching the files modification times for the highest datenums.
%
% Input arguments:
% path: the path to pass to dir. Could be '.', '*.m'. Defaults to working
% directory.
% num: number of entries to return
%
% Outputs:
% A cell array of the num most recently modified files.
%
% Example:
% last_modified('.')
%
% last_modified('/home/matt/matlab', 10); % return the 10 most recently
% modified files.
%
% See also:
% DIR
%
% Matt Foster <ee1mpf@bath.ac.uk>
%
% $Id: /general/last_modified.m 584 2007-03-12T10:07:19.916875Z ee1mpf $
if nargin < 1 || isempty(path)
path = pwd;
end
if nargin < 2
num = 1;
end
% Get a structure of files
files = dir(path);
% Filter out directory (especially the implicit '.' and '..')
files = files(~[files.isdir]);
if num < 2
[dd, mm] = max(datenum({files.date}));
else
[dd, mm] = sort(datenum({files.date}), 'descend');
mm = mm(1:min(end,num));
end
ff = {files(mm).name};
|
|
Contact us at files@mathworks.com