read newest file in loop
7 views (last 30 days)
Show older comments
Hi, I've been working on matlab trying to make a while loop that would read the newest file from a live feed directory, and would stop when there are no new files available.
The whole code is quite big, so I won't post it, but I believe the main problem is this piece here:
dir1=fileList;
[~,dx] = sort([dir1.datenum],'descend');
newest = dir1(dx(end)).name; % returns newest file
which works perfect by itself, but when used more than once it returns the error:
"Dot name reference on non-scalar structure." on "[~,dx] = sort([dir1.datenum],'descend');"
Also tried using
d1 = fileList;
dates = [d1.datenum];
[~, newestIndex] = max (dates);
d1(newestIndex);
d1.date % will display long list of files and stuff, consider deleting...
newest = d1(newestIndex(end)).name;
returns same error.
I've also tried using just the last line i.e.
newest = dir1(dx(end)).name; % returns newest file
But does not seem to refresh the dir in question.
To clarify: - code will check for the newest file available (image) - after process, refresh and check for newest file again, use strcmp to compare filenames and see if new file exists.
- if it does --> loop: run as long as new files arrive.
Hope its more clear now...
Currently, does not appear to discover any newer files than the first instance.. so it doesn't even reach the loop.
Any help is appreciated!
0 Comments
Answers (1)
Walter Roberson
on 10 Nov 2013
You are overwriting FileList with something that is not the result of dir() . For example you might be assigning to it a list of file names at some point.
4 Comments
See Also
Categories
Find more on File Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!