How to detect new files since the last time a code is run?
Mostrar comentarios más antiguos
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)
Respuestas (1)
Sean de Wolski
el 7 de Nov. de 2013
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)
Categorías
Más información sobre Dates and Time en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!