Last active
January 24, 2019 15:36
-
-
Save mattgaidica/37e02cb26581fe6694d3940d054bba99 to your computer and use it in GitHub Desktop.
List or edit recently modified files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function workon(openArr) | |
% (list) >> workon | |
% (open) >> workon(1) | |
% (open) >> workon([2,3,6,14]) | |
% (open) >> workon(1:7) | |
limitTo = 15; % # of files | |
listing = dir('**/*.m'); | |
[~,idx] = sort([listing.datenum],'descend'); | |
if ~exist('openArr','var') | |
clc; | |
headerText = [num2str(limitTo),' MOST RECENT FILES']; | |
disp(headerText); | |
disp(repmat('-',[1,numel(headerText)])); | |
for iFile = 1:min([numel(listing),limitTo]) | |
disp(['[',num2str(iFile,'%02d'),'] --> ',listing(idx(iFile)).name,... | |
' (',timeAgo(listing(idx(iFile)).datenum),')']); | |
end | |
else | |
for iFile = openArr | |
open(fullfile(listing(idx(iFile)).folder,listing(idx(iFile)).name)); | |
end | |
end | |
end | |
function str = timeAgo(dateVector) | |
timeDiff = now - dateVector; | |
daysAgo = timeDiff; | |
if daysAgo < 1 | |
hoursAgo = daysAgo * 24; | |
if hoursAgo < 1 | |
minutesAgo = hoursAgo * 60; | |
if minutesAgo < 1 | |
str = 'now'; | |
else | |
str = [pluralize(minutesAgo,'minute'),' ago']; | |
end | |
else | |
str = [pluralize(hoursAgo,'hour'),' ago']; | |
end | |
else | |
str = [pluralize(daysAgo,'day'),' ago']; | |
end | |
end | |
function str = pluralize(n,str) | |
str = [num2str(round(n)),' ',str]; | |
if round(n) > 1 | |
str = [str,'s']; | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment