How to detect new files since the last time a code is run?

I have a code that searches in a directory for new files. Right now I can get it to either grab the newest file or the files with the maximum date. What I want is for the code to collect all the files that are new since the last time the code was run. How do I do that? Any help would be great.
Code right now....(finds latest file)
d = dir('*.txt');
[x,y] = sort(datenum(char({d.date})))
most_recent_file = char(d(y(end)).name)

Answers (1)

Use logical indexing on the datenums to identify newer ones.
idxNew = datenum(char({d.date})) > datenum(whenever_last_run)
Now use idxNew to keep the ones you want:
dNew = d(idxNew);
As for how you know when this was last run?
You could store this in a *.mat file or as a persistent variable. Depending on what you're doing. To get the current date number
datenum(now)

Categories

Tags

Asked:

on 7 Nov 2013

Answered:

on 7 Nov 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!